Interview Questions

Which style specification method should be used? Why?

CSS Interview Questions and Questions


(Continued from previous question...)

96. Which style specification method should be used? Why?

The answer to this one is tricky. The short answer is: "it depends." The long answer is, however, another story.

If you are planning on using more than one style specification method in your document, you must also worry about Cascading Order of Style methods (see question 11.) If you are going to use only one method, then some guidelines about the nature of each method need to be kept in mind. The answer to this question is also very much related to the advantages and disadvantages to using each of them (next question.)

Method 1: External Style Sheets (The LINK [-->Index DOT Html] element)
This method should be used if you want to apply the same style to multiple documents. Each document can reference the stand-alone style sheet and use the styles contained within. Using this method, the appearance of many documents can be controlled using a single or small number of style sheets. This can save a LOT of time for an author.

Method 2: Embedded Style Sheets (The Style [-->Index DOT Html] element)
The syntax used with Method 2 is the same as that for Method 1. This method is a happy medium between External Style Sheets and Inline Styles (see below.). It should be used in place of Method 1 if you only want to specify styles for a single document. This method should also be used when you want to specify a style for multiple tag types at once or the list of style definitions is of larger size. Method 3: Inline Styles (STYLE attribute to HTML elements)

If you only have to apply style to one or a few elements in a single document, your best bet will often be an Inline Style. This method attaches a style definition within the HTML element it is modifying.

(Continued on next question...)

Other Interview Questions