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.

Want every term in a glossary to look alike without styling each one separately? An internal style sheet puts CSS rules inside a <style> element in the HTML page’s <head>. The rules apply to that page. It’s also called an embedded style sheet. section 7.4 section 7.6

Build a rule in three small steps:

  • Choose a selector, such as dt, to identify the elements to style. section 7.4
  • Put declarations inside braces. Each declaration pairs a property with a value, followed by a semicolon. section 7.4
  • Change the rule once to update every matching element on the page. section 7.6

Give glossary terms one look

<head> <style> dt { font-size: 20px; font-weight: bold; } </style> </head> The dt selector targets each <dt> element. Both declarations apply to every matching term, so there’s no need to repeat a style attribute on each one. section 7.4 section 7.6

Internal styles are handy for a single-page site. On a multi-page site, you would have to copy the <style> element to every page and repeat later edits there. An external style sheet avoids that duplication. section 7.6 section 7.7

<style>    #1  
    div {    #1  
        color: red;    #1  
    }    #1  
</style>    #1  
<div style="color: blue;">    #2  
    What is the color of this text?
</div>

What happens when a rule in <style> says red, but an inline style on the same element says blue? In this example, the inline declaration has greater weight, so the text is blue. section 19.26

Try it: add two <dt> elements, give them one internal style rule, then change the font size. Do both terms change together? section 7.4 section 7.6

How Web Design Playground covers it

How deep it goes
Works through <style> placement and selector–declaration syntax, then explains single-page benefits, multi-page maintenance, and an inline-style conflict.
Examples
Uses bold, resized <dt> glossary terms and a red-versus-blue <div> style conflict.
What it assumes
Introduces CSS declarations and selectors while assuming an HTML page with a head section.
What you can do after
Build it from scratch: place a <style> element in an HTML head and write a rule for repeated page elements.
How it connects
Links CSS selectors and declarations to inline styles, external style sheets, 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.