HTML Styles Guide

Learn how to style HTML elements with CSS

Inline Styles

Styles applied directly to HTML elements using the style attribute

Pros: Highest specificity, quick to implement

Cons: Hard to maintain, not reusable

<p style="color: blue; font-size: 16px;">Text</p>

Internal Styles

Styles defined in the <style> element within the document head

Pros: Applies to whole page, better organization

Cons: Only affects single page

<head> <style> p { color: red; } </style> </head>

External Styles

Styles defined in separate .css files linked via <link> element

Pros: Reusable across pages, best for maintenance

Cons: Additional HTTP request

<head> <link rel="stylesheet" href="styles.css"> </head>

Element

Selects all <p> elements

p { color: blue; }

Class

Selects elements with class='intro'

.intro { font-size: 1.2em; }

ID

Selects element with id='header'

#header { background: #333; }

Attribute

Selects elements with specific attributes

input[type='text'] { border: 1px solid #ccc; }

Pseudo-class

Selects elements in special state

a:hover { color: red; }

Separation of Concerns

Keep content (HTML) separate from presentation (CSS)

Good Example
Bad Example

Specificity

Use classes instead of IDs for styling when possible

Good Example
Bad Example

Responsive Design

Use relative units and media queries for responsive layouts

Good Example
Bad Example

Complete Stylesheet Example

Component Styling

Utility Classes

CSS Playground

Experiment with CSS styling in our live editor

CSS Examples Preview

Ready-to-use examples covering different styling approaches

Live Preview

Styling Methods

Inline Styles

Styles applied directly to HTML elements using the style attribute

Internal Styles

Styles defined in the <style> element within the document head

External Styles

Styles defined in separate .css files linked via <link> element

CSS Features

ElementClassIDAttributePseudo-class

All examples will be loaded into an interactive editor where you can modify and test them

Continue Learning