liveBook · Manning

Internal style

As explained in Web Design Playground

A style sheet embedded in an HTML document, typically within a style element, that applies CSS rules to that document only.

An internal style sheet is CSS tucked inside one HTML page. Put a <style> element in the page’s <head>, then write rules that tell selected elements how to look. It is like giving one page its own small wardrobe. section 7.4

Each style rule has three small parts:

  • A selector chooses the elements to style, often a tag name such as dt. section 7.4
  • A declaration block uses braces to hold one or more declarations. section 7.4
  • Each declaration pairs a property with a value, and semicolons separate declarations. section 7.4

Style every definition term at once

Place this in the head: <style> dt { font-size: 20px; font-weight: bold; } </style> Every dt element on that page receives the same size and bold text. Change the value once, and all of those elements change together. section 7.4 section 7.6

Internal styles are much easier to maintain than repeating inline styles on many elements. They suit a single-page site especially well; across many pages, copying the same <style> element becomes repetitive, so an external style sheet is more practical. section 7.3 section 7.6

<style> 
    selectorA {    #3    #2  
        propertyA1: valueA1;    #1  
        propertyA2: valueA2;    #1  
        ...    #3  
    }    #2  
    selectorB {    #4  
        propertyB1: valueB1;    #4  
        propertyB2: valueB2;    #4  
        ...    #4  
    }    #4  
    ...
</style>

Use this rule-shaped template as a fill-in-the-blanks guide: selector first, declarations inside braces, then another rule if needed. section 7.4

When two style sources disagree, the cascade gives an inline style greater weight than an internal style sheet. For example, an inline blue color overrides an internal rule that sets the same div text to red. section 19.26

How Web Design Playground covers it

How deep it goes
Defines style elements, selectors, declarations, declaration blocks, and rules, then relates internal styles to maintenance and the cascade.
Examples
Uses dt elements styled with larger bold text and a div whose inline blue color overrides an internal red rule.
What it assumes
Introduces internal styles through basic HTML head and style elements while defining CSS rule terminology.
What you can do after
Apply internal rules to multiple matching elements and recognize when inline styles override them.
How it connects
Connects internal style sheets with inline styles, external style sheets, CSS selectors, declarations, and the cascade.

Also explained in

Compare how 2 books explain internal style →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.