⚙️CSS setup
3 ways (and the best way) to add styling to an HTML page
How we can add CSS to an HTML page:
Prerequisites
Code editor
HTML file
Web browser
Methods of adding CSS
For an HTML-only page, we have three ways to add CSS:
In-line (
style
attribute within an HTML tag)<style>
tags (anywhere on an HTML page)External style sheets (outside of the HTML page)
In-line styles
Although not the best practice (or even a good practice), we can learn how CSS works when we write our HTML, by using the style
attribute within each HTML tag:
During development, we can use these in-line styles mainly for testing out a specific styling!
Style tags
We could also use HTML <style>
tags:
However, with more styling rules, this can easily become messy and lengthy!
Style sheets
The "SS" in "CSS" allows us to separate the styling concerns from the HTML file, by placing them into a style sheet:
We then reference the above style.css
file in the HTML page...
using a special
<link>
tag within the<head>
tagwhich itself lives in the
<html>
tag:
Next, we shall learn how to connect those styles in our HTML with CSS selectors...
Last updated