HTML & CSS Basics to Pro
HTML and CSS: Complete Course Notes
Introduction
This course teaches how to build websites from beginner to professional level, culminating in a recreation of youtube.com. No prior coding experience is required. The course covers all major HTML and CSS skills needed to create professional websites.
Required software: Google Chrome (web browser) and VS Code / Visual Studio Code (code editor). Both can be downloaded from their respective websites and installed.
Basics of HTML
HTML stands for Hypertext Markup Language. It is a tool used to create websites. Every website (YouTube, Google, Amazon) uses a combination of HTML and CSS. HTML is essentially giving instructions to a computer step by step to create a webpage.
Creating a First HTML File
Create a folder (e.g.,
html-css-course) and open it in VS Code.Create a new file named
website.html(must end in.htmlto tell the computer it contains HTML code).The first instruction:
<button>Hello</button>creates a button with the text "Hello".Save the file, then open it in Chrome via right-click → Open with Google Chrome.
Another instruction:
<p>Paragraph of text</p>creates a paragraph element.The computer reads HTML code from top to bottom and follows the instructions.
Terminology and Syntax
HTML element: Anything displayed on the webpage (button, paragraph, link, etc.).
Syntax: Rules for how HTML should be written, similar to grammar in English. Unlike English, HTML syntax must be followed exactly.
A tag is written as
<tagname>(opening tag) and</tagname>(closing tag with a slash). The content goes between them.Closing tag has a
/before the tag name.Example:
<button>Hello</button>— opening tag, content, closing tag.
Creating Links
Anchor element:
<a>Link text</a>creates a hyperlink.To set the destination, use the attribute
hrefinside the opening tag:<a href="https://youtube.com">Link to YouTube</a>.hrefis an HTML attribute that modifies how the anchor element behaves (determines where the link goes).Attributes follow syntax: space after tag name, attribute name, equals sign, value in double quotes.
Multiple attributes: separate with a space. Example:
<a href="..." target="_blank">opens link in a new tab.target="_blank"attribute sets the link to open in a new tab.
HTML Quirks
Extra spaces and new lines in HTML are ignored; they appear as a single space on the webpage.
This allows flexible code formatting for readability — indent elements to show nesting.
CSS Basics: Styling Elements
CSS (Cascading Style Sheets) is used to change the appearance of HTML elements. It works alongside HTML to style the webpage.
Writing CSS
Create a
<style>element (usually inside<head>). This element does not appear visually but contains CSS rules.CSS syntax:
selector { property: value; }Selector: tells which elements to target (e.g.,
buttontargets all buttons).Property: what to change (e.g.,
background-color).Value: the new value (e.g.,
red).Colon separates property and value; semicolon ends each style (like a period in English).
Example:
button { background-color: red; color: white; border: none; }styles a button with red background, white text, and no border.
Common CSS Properties
background-color: sets element background.color: sets text color.border: shorthand for border width, style, color (e.g.,border: none;).heightandwidth: set dimensions in pixels (px).border-radius: rounds corners; higher pixels = rounder.cursor: pointer;: changes mouse cursor to a hand when hovering.Trial and error is normal — adjust measurements visually.
Color Values: RGB and RGBA
RGB:
rgb(red, green, blue)where each value is 0–255.rgb(255, 255, 255)= white,rgb(0, 0, 0)= black.
RGBA:
rgba(red, green, blue, alpha)— alpha controls opacity/transparency (0 = fully transparent, 1 = fully opaque).
Targeting Specific Elements: The Class Attribute
Use
classattribute in HTML to label elements:<button class="subscribe-button">.In CSS, target a class with a dot:
.subscribe-button { ... }.Multiple elements can share the same class; class selectors are more specific than element selectors.
Intermediate CSS: Hover, Transitions, Shadows
Hover Effects (Pseudo-class: :hover)
Create a new CSS block:
.selector:hover { ... }Styles inside apply only when the mouse hovers over the element.
Example:
.subscribe-button:hover { opacity: 0.8; }fades the button slightly.Opacity property: value 0 to 1 (0 = fully transparent, 1 = fully opaque).
Active State (:active)
:activestyles apply while the element is being clicked.Example:
.subscribe-button:active { opacity: 0.5; }makes button lighter when clicked.
Transitions
Add
transitionproperty to the base style (not the hover style) to animate changes.Syntax:
transition: property duration;Multiple properties:
transition: background-color 0.15s, color 0.15s;Put transition in the base CSS so it works both on hover in and out.
Common duration:
0.15s(0.15 seconds).
Shadows (box-shadow)
box-shadow: horizontal-offset vertical-offset blur color;Example:
box-shadow: 5px 5px 10px rgba(0,0,0,0.15);Use
rgbafor natural, subtle shadow colors.To make shadow appear only on hover, put the
box-shadowproperty inside the:hoverstyle.Transition the shadow by adding
box-shadowto the transition list.
Chrome DevTools
Open by right-clicking any webpage element → Inspect.
Shows all HTML and CSS of the page.
Pointer icon (top left) lets you hover over any visible element to highlight its HTML and see its applied styles.
Computed tab shows final calculated styles (including exact colors, heights, etc.).
Use DevTools to get precise color values (RGB or HEX) from any website to copy into your own code.
CSS Box Model
Every element is a box. The box model consists of:
Margin: space outside the element (between elements).
Border: outer edge (width, style, color).
Padding: space inside the element (between content and border).
Content: the actual content (text, image, etc.).
Margin
margin-top,margin-right,margin-bottom,margin-leftShorthand:
margin: top right bottom left;ormargin: vertical horizontal;Negative margin pulls the element toward that side.
Padding
padding-top,padding-right,padding-left,padding-bottomShorthand works the same as margin.
Avoiding Fixed Height/Width
Instead of setting exact
heightandwidth, use padding to create spacing inside the element; the element will resize automatically to fit its content.Use
vertical-align: top;on inline-block elements to align them to the top.
Styling Text
Common Text Properties
font-family: sets the font (e.g.,Arial,Times New Roman). Use a comma-separated font stack for fallbacks:font-family: Arial, Helvetica, sans-serif;font-size: size in pixels.font-weight: boldness (e.g.,bold,normal,700,500).font-style: italic;text-align: center(orleft,right).line-height: space between lines (e.g.,20px).text-decoration: underline;(ornone,line-through).
HTML Entities for Special Characters
Special characters (e.g., middle dot
·, checkmark✓, greater than>) are created using HTML entities.Example:
·for middle dot,✓for checkmark.Search "HTML entity [character]" to find the code.
Span Element (Inline Text Container)
<span>is a generic inline text element with no default styles.Use it to style a specific part of text without affecting the whole paragraph.
Assign a class to the
<span>and style it with CSS (including hover effects).
Resetting Default Margins
Paragraphs (
<p>) have default margin top and bottom.Use
p { margin: 0; }to remove them, then set custom margins as needed.
CSS Specificity
When multiple styles target the same property, the browser uses specificity to decide which wins.
Class selectors (
.class) are more specific than element selectors (p,div).More specific selectors override less specific ones.
HTML Structure: Proper Webpage Setup
Document Type Declaration
Every HTML file should start with
<!DOCTYPE html>to tell the browser to use modern HTML.
HTML, Head, Body
<!DOCTYPE html>
<html>
<head>
<!-- Meta info, title, CSS links, style elements -->
</head>
<body>
<!-- Visible page content -->
</body>
</html><html>element contains the entire webpage.<head>contains non-visible elements:<title>,<style>,<link>, etc.<body>contains all visible content (text, images, buttons, etc.).
Title Element
<title>Page Title</title>sets the text in the browser tab.
Live Server Extension
Install Live Server in VS Code to automatically reload the webpage whenever code changes.
Right-click the HTML file → Open with Live Server.
Works only after adding the proper HTML structure (
<!DOCTYPE html>,<html>, etc.).
Linking External CSS
Use
<link>element in<head>:<link rel="stylesheet" href="styles.css">rel="stylesheet"indicates the linked file is a stylesheet.hrefis the file path (can include folder names:styles/main.css).
File Paths
href="buttons.css"— file in the same folder as the HTML.href="styles/buttons.css"— file inside a subfolder namedstyles/.Use forward slashes
/to separate folder names.
Google Fonts
Go to fonts.google.com, select a font, pick styles, then copy the
<link>code into the<head>.Use the font name in
font-family(e.g.,font-family: 'Roboto', Arial;).
Images and Inputs
Image Element
<img src="path/to/image.jpg">— void element, no closing tag.srcattribute: file path to the image.Width and height can be set in CSS. If only
widthis set,heightadjusts to maintain aspect ratio.object-fit: cover;andobject-fit: contain;control how an image fits its container.object-positionadjusts which part of the image is visible.
Input Element
<input type="text" placeholder="Search">creates a text input box.type="checkbox"creates a checkbox.placeholderattribute shows hint text inside the field, which disappears when typing.Inputs are inline-block by default (can appear beside other elements).
Display Property
Three Basic Display Types
Block elements (e.g.,
<p>,<div>,<h1>): take up the entire line; start on a new line and stretch to fill the container width.Inline-block elements (e.g.,
<img>,<input>): only take as much width as needed; can appear beside each other.Inline elements (e.g.,
<span>,<strong>,<a>): appear within a line of text; do not create line breaks.
Changing Display with CSS
display: block;forces any element to become a block element.display: inline-block;forces an element to become inline-block.display: inline;makes an element inline (but loses ability to set width/height).The display property controls whether elements appear on the same line or on separate lines.
Div Element (Containers)
<div>is a division or box — a generic container element.By default,
<div>is a block element (takes full width of its parent).Convert to
display: inline-block;to make it sit beside other elements.Key feature: a
<div>can contain any other elements (paragraphs, images, other divs) — it is a container.Using divs, we group related elements together and style them as a unit. This is how complex layouts are built.
Nested Layouts Technique
Two fundamental layout types:
Vertical layout: items stacked on top of each other (using block elements or
flex-direction: column).Horizontal layout: items beside each other (using inline-block, flexbox, or grid).
Complex designs are broken down into nested combinations of vertical and horizontal layouts.
Example: A YouTube video preview may have a vertical layout (thumbnail on top, text below), with the text section containing a horizontal layout (channel icon left, title/statistics right), and that right part containing another vertical layout (title, author, stats).
CSS Grid
CSS Grid is a powerful layout system for creating rows and columns.
Creating a Grid
Set
display: grid;on the container.Define columns with
grid-template-columns: 100px 100px 100px;(three columns of given widths).The number of values determines the number of columns; the values determine their widths.
Child elements automatically placed into grid cells; if more elements than columns, new rows are created.
The fr Unit
1fr(fraction) takes up the remaining space after other columns are sized.Multiple
frvalues distribute remaining space proportionally (e.g.,1fr 2frgives the second column twice the remaining space of the first).Use
frfor responsive columns that resize with the page.
Grid Gaps
column-gap: 20px;— space between columns.row-gap: 40px;— space between rows.
Grid vs. Flexbox
Grid is more rigid: you define columns first, and elements are placed into them.
Flexbox is flexible: elements control their own sizing, and they can wrap and reflow.
Use grid when you care more about the layout structure; use flexbox when you care more about the content's sizing.
Flexbox
Flexbox is used for flexible one-dimensional layouts (rows or columns).
Creating a Flex Container
display: flex;on the container.flex-direction: row;(default) arranges children horizontally;flex-direction: column;arranges them vertically.
Justify Content (Horizontal Alignment with flex-direction: row)
justify-content: flex-start;(default) — aligns items to the start.justify-content: flex-end;— to the end.justify-content: center;— center.justify-content: space-between;— equal space between items (first and last at edges).justify-content: space-around;— equal space around each item.
Align Items (Vertical Alignment with flex-direction: row)
align-items: stretch;(default) — items stretch to fill container height.align-items: flex-start;— items at top.align-items: flex-end;— items at bottom.align-items: center;— vertically centered.
Flex Property on Children
flex: 1;on a child makes it take up the remaining space (like1frin grid).A higher number (e.g.,
flex: 2;) gives it twice the remaining space compared to a child withflex: 1.flex-shrink: 0;prevents an element from shrinking when the container gets smaller.
Flexbox Nesting
Flexbox only affects direct children. To control alignment of grandchildren, those containers must also be flexboxes.
CSS Position
Position adds another dimension — elements can be placed on top of others or stick to the screen while scrolling.
Position Properties
position: static;— default; normal document flow.position: fixed;— element is positioned relative to the browser window; it stays in place when scrolling.position: absolute;— element is positioned relative to the nearest positioned ancestor (an ancestor withposition: relative,absolute, orfixed); otherwise relative to the page.It is removed from normal document flow (does not affect other elements' positions).
position: relative;— element remains in normal flow, but can be offset usingtop,left,bottom,right; also becomes the reference for any absolutely positioned children.
Positioning Values
top,left,bottom,right: distance from the corresponding edge of the positioned ancestor (or page).Use negative values to move beyond the edge.
widthandheightcan also be set alongside these properties.
Z-Index
Controls stacking order of positioned elements.
Higher
z-indexvalues appear in front.Only works on elements with a
positionvalue other thanstatic.
Common Use Cases
Fixed header:
position: fixed; top: 0; left: 0; right: 0; height: 55px;Fixed sidebar:
position: fixed; left: 0; top: 55px; bottom: 0; width: 72px;Badge on top of icon (e.g., notification count): Use
position: absolute; top: -2px; right: -5px;inside aposition: relative;container.Video time overlay on thumbnail: Same technique: container
position: relative;and time elementposition: absolute; bottom: 8px; right: 5px;
Tooltips
A tooltip appears when hovering over an element.
Create a
<div>with tooltip text inside the button/icon container.Container:
position: relative;Tooltip:
position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%);(or use flexbox to center).Set
opacity: 0;andpointer-events: none;on the tooltip.Use
transition: opacity 0.15s;On hover of the container, set tooltip
opacity: 1;using CSS:.container:hover .tooltip { opacity: 1; }Use
white-space: nowrap;to prevent text wrapping.
Responsive Design with Media Queries
Media queries allow CSS to apply only under certain conditions (e.g., screen width).
Syntax:
@media (max-width: 750px) { ... }— styles inside apply when screen width is 750px or less.@media (min-width: 1000px) { ... }— styles apply when screen width is 1000px or more.Combine:
@media (min-width: 751px) and (max-width: 999px) { ... }Use media queries to change the number of grid columns, font sizes, or layout at different screen sizes.
CSS Shorthand Properties
Padding and Margin
padding: 4px;→ all four sides = 4px.padding: 4px 10px;→ vertical (top/bottom) 4px, horizontal (left/right) 10px.padding: 10px 20px 30px 40px;→ top, right, bottom, left (clockwise).Same shorthand works for
margin.
Border
border: 1px solid gray;replacesborder-width: 1px; border-style: solid; border-color: gray;
Background
background: white;shorthand forbackground-color.
Inheritance
Certain CSS properties (mostly text-related) are inherited from parent to child elements.
Inherited properties:
font-family,font-size,font-weight,color,line-height,text-align, etc.Non-inherited properties:
border,padding,margin,background-color,width,height, etc.Set a default font on
<body>to have it apply to all text on the page.More specific selectors (e.g.,
.video-title) override inherited values (due to specificity).
Semantic HTML
Semantic elements describe the meaning of the content, not just its appearance.
Examples:
<header>,<nav>,<main>,<section>,<article>,<footer>,<aside>.They function exactly like
<div>but provide structure for screen readers and search engines.Replace generic divs with appropriate semantic elements to improve accessibility and SEO.
<header>...</header>
<nav>...</nav>
<main>
<section>...</section>
</main>Comments
Comments are ignored by the browser and useful for documenting code.
HTML comment:
<!-- This is a comment -->CSS comment:
/* This is a comment */
Final Project: YouTube Clone
The course culminates in building a YouTube-style page with:
Header: fixed at top, contains left section (hamburger menu, YouTube logo), middle section (search bar, search button, voice search button), right section (upload, apps, notifications with badge, user profile picture).
Sidebar: fixed on left, contains links with icons and text, turns gray on hover.
Video preview grid: uses CSS grid with responsive number of columns via media queries.
Video preview cards: nested layouts — vertical layout for thumbnail row and info row; horizontal layout for channel picture and video details; tooltips on header icons; video time overlay on thumbnails.
The project is built step by step, demonstrating all major skills: HTML structure, CSS styling, box model, display, flexbox, grid, position, transitions, and responsive design.
Next Steps
Beyond HTML and CSS, learning JavaScript is the natural next step to make webpages interactive (handling clicks, user input, dynamic content updates). A full JavaScript course for beginners is available from the same creator.
Key Takeaway: Creating websites is a process of breaking down a design into smaller layouts (using nested layouts), then building each part with HTML and styling it with CSS one property at a time. Use Google and DevTools to discover unknown properties and perfect designs.

Ask anything
We've read this whole study set, so questions about it get the best answers.