HTML and CSS · Lesson 1 of 12
How a web page is built
Every page you've ever seen is built from two languages: HTML says what things are, and CSS says how they look. The browser reads both and paints the page.
Elements, tags and attributes
HTML is made of elements. Most have an opening tag, content and a closing tag: <p>Hello</p>. Some have no content, like <img>. Extra information goes in attributes inside the opening tag: <a href="/about/">.
Elements nest inside each other like boxes inside boxes. Change the text below and watch the page change.
The skeleton of every page
A full page has the same outline: a <!doctype html> line, an <html> element holding a <head> (information about the page: its title, its character set, links to CSS) and a <body> (everything you see).
The <meta name="viewport"> line makes the page fit phone screens; without it, phones zoom out to show a desktop-width page.
Where CSS goes
CSS can sit in three places: in a style attribute on one element (avoid it), in a <style> element in the head, or in a separate .css file linked with <link rel="stylesheet" href="style.css">, which is what real sites use, so many pages can share one file.
A CSS rule is a selector (which elements) and declarations (property: value).
Your turn
Make a heading with your name, a paragraph about what you're learning, and a link to your favourite website. Make the heading blue.
Show a solution
<style>
h1 { color: #1971c2; }
</style>
<h1>Ravi Kumar</h1>
<p>I'm learning HTML and CSS.</p>
<a href="https://example.com">My favourite site</a>In the interview
What is the difference between HTML and CSS?
HTML describes the content and its structure (this is a heading, this is a list); CSS describes how it looks (colours, sizes, layout). Keeping them apart lets one HTML page be restyled without touching its content.
What does <!doctype html> do?
It tells the browser the page is modern HTML, so it renders in standards mode. Without it, browsers fall back to "quirks mode", which copies old, buggy behaviour.
What is the viewport meta tag for?
It tells phones to use the device's width for the page instead of pretending to be a 980 px desktop and zooming out. Without it, responsive CSS doesn't work on phones.