Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:47:30+00:00 2026-06-15T19:47:30+00:00

About HTML class attribute assigned with two or more class names, that is, <tag

  • 0

About HTML class attribute assigned with two or more class names, that is,

<tag class="a b">....</tag>

I can test it with different browsers — see tests at http://jsfiddle.net/PP9yf/1/ or this question/answer
— and deduce a common sense rule:

use class="a" if it is defined, or use class="b" if it is defined, or use BOTH if both defined… And, when using both, if they assign same property, the last CSS definition overrides the others.

So, we can interpret for example that class="a b" must be the same as class="b a".

But it is a W3C official interpretation?

Where the W3C standard that say this rule?


PS: I started with this other question, but my motivation is software development. I need this normative answer to develop a software similar to emogrifier, etc.

Example: CssToInlineStyles need this correction… But only need a "correction" IF there are a W3C standand saying that the software is wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:47:31+00:00Added an answer on June 15, 2026 at 7:47 pm

    Your findings are correct, and they are official W3C specification.

    Two classes on the element itself have the same ‘origin’. Also, the selectors have the same ‘weight’.
    Since these and other rules don’t determine which style has priority, the order of the style sheet determines the overrule.

    See Cascading Style Sheets, level 1, paragraph 3.2 for the rule that specifies this. 3.2.1 through 3.2.4 don’t differentiate between any of the two styles. It is 3.2.5 that prevails.

    I will cite the rules here, although you may want to read the document to place them in context.

    Conflicting rules are intrinsic to the CSS mechanism. To find the value for an element/property combination, the following algorithm must be followed:

    1. Find all declarations that apply to the element/property in question. Declarations apply if the selector matches the element in
      question. If no declarations apply, the inherited value is used. If
      there is no inherited value (this is the case for the ‘HTML’ element
      and for properties that do not inherit), the initial value is used.
    2. Sort the declarations by explicit weight: declarations marked ‘!important’ carry more weight than unmarked (normal) declarations.
    3. Sort by origin: the author’s style sheets override the reader’s style sheet which override the UA’s default values. An imported style
      sheet has the same origin as the style sheet from which it is
      imported.
    4. Sort by specificity of selector: more specific selectors will override more general ones. To find the specificity, count the number
      of ID attributes in the selector (a), the number of CLASS attributes
      in the selector (b), and the number of tag names in the selector (c).
      Concatenating the three numbers (in a number system with a large base)
      gives the specificity.
    5. Sort by order specified: if two rules have the same weight, the latter specified wins. Rules in imported style sheets are considered
      to be before any rules in the style sheet itself.

    Summarizing

    We can translate the common sense rule itens in the W3C CSS1 rule 3.2 itens,

    • «use class="a" if it is defined, or use class="b" if it is defined, or use BOTH if both defined» is equivalemnt to 3.2.1, «Declarations apply if the selector matches the element in question».

    • «the last CSS definition overrides the others» is equivalemnt to 3.2.5 , «the latter specified wins».

    Not changed with new standars: CSS2, CSS2.1 and CSS3 use the same rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

About HTML class attribute, that assigns CSS class (or classes?) to a tag. The
I just read about HTML 5's WebSocket interface. How can I start trying this?
can I programatically (or, as we're speaking about html and css , semantically) decide
How can I go about cropping a HTML canvas around only it's content? I
So I have this php script that output an html table with data about
I've extended the HTML helper with a method that needs an attribute value from
I'm a little confused about CSS and the class attribute. I always thought, the
I would like to learn about HTML forms. For example, I have 2 input
Everyone, every blog is talking about HTML 5 and giving solution to use HTML
Here's what I'm trying to achieve: Before: www.example.com/index.php?page=about&pg=5 After: www.example.com/about.html?pg=5 The URL must specifically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.