CSS controls how HTML content looks and is laid out. A CSS rule selects one or more elements, then applies property–value declarations to them. This tutorial walks through the rule syntax, common features, selector types, and practical examples—and explains why “CSS3” is now a familiar umbrella label rather than one finished, all-encompassing specification.
What CSS does—and what “CSS3” means
CSS (Cascading Style Sheets) describes how structured documents such as HTML are rendered. It controls presentation: typography, colors, spacing, borders, layout, and more. A stylesheet can be placed in a separate file, embedded in an HTML document, or—in limited cases—written inline on an element. Keeping most styles in a stylesheet makes them easier to reuse and maintain.
“CSS3” remains a common name for learning material about modern CSS, but it does not describe one final version that contains every current feature. CSS is developed as a set of modules, which evolve on their own schedules. W3C’s specifications index and overview track that modular landscape; the index includes snapshots through 2026. A feature’s inclusion in a snapshot is not a guarantee that every browser implements it. W3C’s CSS overview and CSS specifications index are useful references for the distinction.
CSS rule syntax
A basic rule has a selector followed by a declaration block. The selector identifies the elements to style; each declaration pairs a property with a value.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
p {
color: rebeccapurple;
line-height: 1.5;
}
pis the selector; it matches paragraph elements.colorandline-heightare properties.rebeccapurpleand1.5are their values.- Braces enclose the declarations, and a semicolon separates declarations.
For example, save the rule in styles.css and link that file from the document’s <head>:
<link rel="stylesheet" href="styles.css">
The browser applies matching rules to the document, then resolves competing declarations through the cascade. Selector matching and the cascade are related but different: a selector determines which elements a rule targets, while the cascade determines which applicable declaration wins when rules conflict.
Common CSS features in context
CSS covers much more than text color. These examples show common ways to shape a page while keeping styles tied to meaningfully selected elements.
Typography and color
body {
font-family: system-ui, sans-serif;
color: #222;
line-height: 1.5;
}
h1 {
color: #174a7e;
font-size: 2rem;
}
The font-family, color, and font-size properties affect text appearance. A unitless line-height such as 1.5 scales with the element’s font size.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Spacing and borders
.notice {
padding: 1rem;
margin-block: 1rem;
border: 1px solid #8ab;
border-radius: 0.5rem;
}
padding adds space inside the element’s border; margin adds space outside it. Logical properties such as margin-block describe a direction relative to the writing mode, rather than assuming that the page always flows left to right.
Layout with Flexbox
.toolbar {
display: flex;
align-items: center;
gap: 1rem;
}
Flexbox arranges items along a flexible axis and is useful for rows or columns such as toolbars. gap sets spacing between items without adding margins to each child.
Layout with Grid
.cards {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 1rem;
}
@media (max-width: 40rem) {
.cards {
grid-template-columns: 1fr;
}
}
Grid is useful when a layout needs rows and columns. This example uses two equal columns above a chosen viewport width and one column at or below it. The breakpoint is a design choice, not a universal device boundary; adjust it to where the content needs more room.
CSS selectors: what they match
Selectors choose elements by type, class, ID, attribute, state, or position in the document tree. The CSS Selectors Level 3 specification describes established selector syntax, while MDN’s guide covers the broader selector landscape and notes support details. W3C Selectors Level 3 and MDN’s CSS selectors guide provide further reference.
Recommended Free Tools
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Type, class, and ID selectors
p { color: #333; }
.notice { padding: 1rem; }
#main-content { max-width: 70ch; }
pmatches paragraph elements..noticematches elements whose class list includesnotice. Classes are typically reusable across multiple elements.#main-contentmatches an element whose ID value ismain-content. Use an ID when the target is identified by that value; unlike a class, an ID selector is not a reusable category selector.
HTML authors are expected to use an ID value as an element identifier, but selector matching should not be confused with a guarantee that malformed or duplicated IDs cannot occur in a document.
Attribute selectors
input[type="email"] {
border-color: teal;
}
This selector matches an <input> element whose type attribute is exactly email. Attribute selectors can target markup values without adding another class solely for styling.
Pseudo-classes for states and positions
a:hover {
text-decoration: underline;
}
li:first-child {
font-weight: bold;
}
A pseudo-class adds a condition to a selector. Here, :hover matches a link while it is hovered, and :first-child matches an element that is the first child of its parent. For interactive controls, do not rely on hover alone: consider keyboard interaction and visible focus states as well.
Combinators for document relationships
nav > a { margin-inline-end: 1rem; }
article p { line-height: 1.6; }
h2 + p { margin-block-start: 0; }
h2 ~ p { color: #444; }
- A space, as in
article p, is the descendant combinator: it matches paragraphs anywhere inside an article. >, as innav > a, is the child combinator: it matches links that are direct children of a navigation element.+, as inh2 + p, is the adjacent sibling combinator: it matches a paragraph immediately following anh2with the same parent.~, as inh2 ~ p, is the subsequent sibling combinator: it matches paragraphs that follow anh2and share its parent, even if other siblings are between them.
In the code sample, the leading spaces before the last two selectors are harmless CSS whitespace; they do not change which elements those selectors match.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Putting selectors together in an HTML example
Given this markup:
<main id="main-content">
<nav>
<a href="/guide">Guide</a>
<a href="/examples">Examples</a>
</nav>
<article>
<h2>Getting started</h2>
<p class="notice">Start with a small rule.</p>
<label>Email <input type="email"></label>
</article>
</main>
These rules target different parts of the same document:
#main-content { max-width: 70ch; }
nav > a { margin-inline-end: 1rem; }
article p.notice { padding: 1rem; }
input[type="email"] { border-color: teal; }
The ID rule selects the main container; the child rule selects its direct navigation links; the compound selector article p.notice selects a paragraph with the class notice inside an article; and the attribute selector selects the email input. A compound selector adds conditions to one element, while a combinator expresses a relationship between elements.
Choosing a selector and understanding the cascade
Prefer a selector that communicates the intended target without depending unnecessarily on document structure. A class is often a practical choice for a reusable visual category. A type selector is useful when a style should apply broadly to that kind of element. Attribute, state, and structural selectors can avoid extra markup when the target is genuinely defined by those conditions.
Specificity affects how competing declarations are resolved, but it is not the only cascade factor. A selector matching an element does not mean its declaration always wins: other applicable declarations and cascade rules may take precedence. Avoid making selectors needlessly complex just to override earlier styles; simpler, reusable rules are easier to change safely.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Checking support for newer CSS
Do not infer browser support from a feature’s name, age, or position in a specification. Specification maturity and implementation are separate questions. The W3C explains that snapshot inclusion is based on stability, not expected browser adoption; the CSS Snapshot 2025 (a W3C Note dated 25 February 2025) makes that distinction explicit. The W3C overview identifies CSS Snapshot 2026 as the latest stable snapshot at the time represented by the specifications index, so the 2025 document should not be treated as a newer snapshot.
Before depending on a newer selector or property in production:
- Look up the specific feature in a current compatibility reference, such as MDN’s selector guide.
- Check the browsers and versions your site needs to support; “supported” is not a universal yes-or-no independent of your audience.
- Provide a fallback or a progressive enhancement where older or unsupported browsers need a usable experience.
- Test the rendered page in the relevant browsers, especially if the feature affects layout or access to important content.
Preview the page you styled
A browser is the most direct place to inspect CSS while developing: open the page, resize the viewport, and use developer tools to see which rules match and which declarations are overridden. For a repeatable visual snapshot, capture a page at a known URL and viewport. ScreenshotNeo is a website screenshot API and MCP server; its API can return a screenshot or PDF from a URL.
Or skip the browser setup
Make one GET request after your styled page is reachable at a URL. Replace the target URL with your own page and use the appropriate output filename for the format you request. See the ScreenshotNeo documentation for request parameters and response behavior.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo removes known cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.
Common CSS troubleshooting
A rule does not seem to apply
- Confirm the stylesheet is linked at the correct path and actually loaded.
- Check that the selector matches the element’s tag, class, ID, attributes, or document relationship as written.
- Inspect the element in browser developer tools to see whether another declaration wins in the cascade.
- Check for a syntax error, such as a missing brace or misspelled property, near the rule.
A selector matches too many or too few elements
Check the actual document tree. A descendant selector matches at any depth; a child selector only matches direct children. Confirm class spelling and attribute values in the HTML, and use the browser’s element inspector to identify the matched nodes.
A newer selector behaves differently across browsers
Verify support for that exact selector in the browsers and versions you target. A W3C specification snapshot describes specification status, not universal implementation. Where support is insufficient, use a simpler established selector or provide a fallback.
Changes appear in the file but not on the page
Check that you edited the stylesheet the page uses, then reload and inspect the loaded CSS in developer tools. A cached file or an incorrect link path can make a valid edit appear ineffective.
Quick Recap
Further reference
- W3C: Cascading Style Sheets overview
- W3C: All CSS specifications
- W3C: Selectors Level 3
- MDN: CSS selectors guide
- W3C: CSS Snapshot 2025
- W3C: CSS Snapshot 2024
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




