1D0-520 · Question #116
Which attribute should be used to assign inline styles to HTML?
The correct answer is B. style. See the full explanation below for the reasoning.
Question
Which attribute should be used to assign inline styles to HTML?
Options
- Aid
- Bstyle
- Cvalue
- Dclass
How the community answered
(38 responses)- A5% (2)
- B74% (28)
- C13% (5)
- D8% (3)
Community Discussion
4The answer is B, style. The style attribute is what lets you write CSS directly inside an HTML tag, so if you want to, say, turn text red right there on the element without touching a separate stylesheet, you write style="color: red;" and it applies just to that tag.
The answer is B, style. The style attribute is the one HTML gives you specifically for writing inline CSS declarations directly on an element, like style="color:red;font-size:14px;" and it takes a semicolon-separated list of property-value pairs. The other choices are easy to eliminate once you know what each attribute does: id and class are used for targeting elements with external or embedded CSS, not for writing the rules themselves, and value is for form elements like input to set a default value. Qualifier words did not really change this question, but watch for questions that ask about "best practice" versus "which attribute is valid" because inline styles are valid but external stylesheets are generally preferred for maintainability.
Style attribute, obviously, but do you know why id and class cannot apply inline styles directly?
Right, and the way I think of it is that id and class are just labels the browser uses to match rules in a separate stylesheet, so without that external or internal CSS to actually pair with them, they carry no styling instructions on their own.