HTML and CSS for absolute beginners: what they do, your first web page, styling basics and free resources to keep learning.
Embarking on Your Web Development Journey: The Foundation of HTML
The digital world we inhabit is a tapestry woven with intricate code, yet at its very core lies a remarkably accessible pair of languages: HTML and CSS. For anyone contemplating a foray into web development, understanding these foundational technologies isn't just recommended; it's absolutely essential. Think of HTML as the skeletal structure of a building, defining its rooms, walls, and doorways.
CSS, on the other hand, is the interior decorator and architect, dictating the paint colors, furniture styles, and overall aesthetic. Together, they form the bedrock upon which all modern websites are built, from a simple personal blog to a sprawling e-commerce empire. This guide aims to demystify these powerful tools, providing an absolute beginner's roadmap to their fundamental concepts and practical application.
What is HTML and Why Does It Matter?
HTML, which stands for HyperText Markup Language, isn't a programming language in the traditional sense. It doesn't execute complex logic or perform calculations. Instead, it's a markup language, meaning it uses a system of tags to structure content on the web. These tags tell web browsers how to display information – whether it's a heading, a paragraph, an image, a link, or a list.
Without HTML, the internet would be a chaotic jumble of raw text, devoid of any discernible organization or meaning. Every webpage you've ever visited, regardless of its complexity or sophistication, relies on HTML to define its underlying structure. It's the universal language that browsers understand, allowing them to render content consistently across different devices and operating systems.
The Anatomy of an HTML Document
An HTML document is essentially a plain text file saved with an .html or .htm extension. While you can technically write HTML in any text editor, using a dedicated code editor (like Visual Studio Code, Sublime Text, or Atom) is highly recommended for features like syntax highlighting and auto-completion.
The DOCTYPE Declaration
Every HTML document should begin with a declaration. This isn't an HTML tag itself but an instruction to the web browser about which version of HTML the document is written in. For modern web development, signifies that the document adheres to HTML5 standards, the latest and most widely used version. It ensures that browsers render the page in "standards mode," preventing compatibility issues.
The Element
Following the DOCTYPE declaration, the entire HTML document is encapsulated within the and tags. This element acts as the root of the document, containing all other HTML elements. It often includes a lang attribute, like , to declare the primary language of the document, which can be beneficial for accessibility and search engine optimization.
The Section
The section contains metadata about the HTML document – information that isn't directly displayed on the webpage itself but is crucial for its proper functioning and presentation.
The Tag
One of the most important elements within the is the tag. The text enclosed within this tag appears in the browser's title bar or tab. It's vital for user experience and search engine visibility, as it often forms the clickable link in search results.
Meta Tags
Meta tags () provide additional metadata about the HTML document. Common examples include:
: Specifies the character encoding for the document, ensuring that special characters and symbols are displayed correctly. UTF-8 is the universally recommended encoding.: Essential for responsive web design, this meta tag tells browsers to set the viewport width to the device width and to set the initial zoom level to 100%.: Provides a concise description of the webpage for search engines.: (Less relevant for SEO nowadays, but historically used) Lists keywords associated with the page content.
Linking External Resources
The is also where you link external resources like CSS stylesheets and JavaScript files, which we'll touch upon later. For CSS, you'll typically use the tag: .
The Section
The section contains all the visible content of the HTML document. Everything you see on a webpage – text, images, videos, forms, buttons – is placed within the and tags. This is where the structural elements that define your content reside.
If you're just starting out with web development, you might find the article on HTML and CSS for Absolute Beginners particularly helpful. It provides a comprehensive introduction to the basics of these essential web technologies, making it easier for newcomers to grasp fundamental concepts. For more insights and resources, you can check out this related article at Enda Storrie's website.
Structuring Content with HTML Tags
HTML provides a rich set of tags to structure and organize your content effectively. Understanding these fundamental tags is key to building meaningful and accessible web pages. Each tag serves a specific purpose, and using the correct tag for the correct content is crucial for both readability and search engine optimization.
Headings and Paragraphs
Headings are used to introduce sections of content and provide a hierarchical structure. HTML offers six levels of headings, from
(the most important) to
(the least important).
Heading Tags (
to
)
should be used for the main title of the page or the most important heading. There should generally only be one
per page.
tags are used for major sections within the page.
tags are for sub-sections of Discover a new way to collaborate on storytelling with Chain Story Online. Writers from around the world can contribute to ongoing narratives at Chain Story Online. Unleash your creativity and join the community at Chain Story Online.
.
- And so on, down to
.
to
)
should be used for the main title of the page or the most important heading. There should generally only be one
per page.
tags are used for major sections within the page.
tags are for sub-sections of Discover a new way to collaborate on storytelling with Chain Story Online. Writers from around the world can contribute to ongoing narratives at Chain Story Online. Unleash your creativity and join the community at Chain Story Online.
.
.Example:
```html
My First Website
If you're just starting your journey into web development, understanding the basics of HTML and CSS is essential. For those looking to enhance their skills further, you might find it helpful to explore related topics that delve into practical applications. One such article that offers insights into outdoor adventures while also providing a unique perspective on web design is Conquering Nephin: A Walk to the Summit. This piece not only captures the beauty of nature but also serves as an inspiration for creating visually appealing web pages that can showcase similar adventures.
+ Join Our Writing Community for FREE
Chain Story Online
Fun, free, flash fiction writing with writers just like you. You have ~100 words to begin a story or continue a story and make it yours.
Story Bible Studio
Digital space for writers to plot, plan, and build better stories. Designed by writers for writers. Your final draft awaits.
About Me
My Hobbies
Reading
```
Paragraphs (
) are used to define blocks of text. The browser automatically adds some spacing above and below paragraphs, making text more readable.
Example:
```html
This is a paragraph of text. It contains information about the topic at hand. Paragraphs are fundamental for presenting textual content on a webpage.
Here's another paragraph, demonstrating how multiple paragraphs stack vertically on a page.
```
Lists and Links
Lists are essential for organizing information into digestible formats. HTML supports ordered lists, unordered lists, and description lists. Links are the backbone of the internet, allowing users to navigate between pages and resources.
Ordered Lists (
) and Unordered Lists (
)
- An ordered list (
) is used for items where the order matters, and browsers typically display them with numbers. Each item within an ordered list is enclosed in an(list item) tag. - An unordered list (
) is used for items where the order doesn't matter, typically displayed with bullet points. Each item within an unordered list is also enclosed in antag.
Example:
```html
My Favorite Fruits (Unordered)
- Apples
- Bananas
- Oranges
Steps to Make Coffee (Ordered)
- Boil water.
- Add coffee grounds to a filter.
- Pour hot water over grounds.
- Enjoy!
```
Hyperlinks ()
Hyperlinks, or anchors, are created using the tag. The href attribute within the tag specifies the destination URL.
Example:
```html
Visit the Google website for more information.
Check out our About Us page.
```
The target="_blank" attribute can be added to open the link in a new tab: External Link.
Images and Other Media
Images are vital for visual appeal and conveying information quickly. HTML uses the tag to embed images.
Images (![]()
)
The tag is a self-closing tag (it doesn't have a separate closing tag). It requires at least two attributes:
src: Specifies the path to the image file. This can be a relative path (e.g.,images/picture.jpg) or an absolute URL (e.g.,https://www.example.com/images/picture.jpg).alt: Provides alternative text for the image. This text is displayed if the image fails to load or if a screen reader is being used, making your website more accessible.
Example:
```html

```
The width and height attributes can be used to define the image's dimensions, though it's often better practice to control image sizing with CSS.
If you're just starting your journey into web development, understanding the basics of HTML and CSS is essential for building a strong foundation. For those looking to expand their skills beyond the basics, you might find it helpful to explore how these technologies can be integrated into more complex platforms. A great resource for this is an article that discusses the benefits of using WordPress for creating effective websites. You can read more about it in this insightful piece on unleashing the power of WordPress, which highlights how mastering HTML and CSS can enhance your website's functionality and design.
Styling Your Webpage with CSS
While HTML provides the structure, CSS (Cascading Style Sheets) is what brings your webpages to life with colors, fonts, layouts, and animations. Without CSS, websites would look like plain, unformatted documents from the early days of the internet. CSS allows you to separate the presentation of your document from its content, making your code cleaner, more maintainable, and easier to adapt for different devices.
What is CSS and How Does It Work?
CSS is a styling language that describes how HTML elements should be displayed on screen, paper, or in other media. It works by targeting specific HTML elements and applying a set of styling rules to them. These rules consist of properties (like color, font-size, margin) and their corresponding values (like blue, 16px, 20px).
Three Ways to Add CSS
There are three primary methods to incorporate CSS into your HTML document, each with its own use cases and implications.
Inline Styles
Inline styles are applied directly to individual HTML elements using the style attribute. This method is generally discouraged for larger projects because it mixes content and presentation, making the code harder to read, maintain, and update. It's best reserved for very small, unique styling adjustments.
Example:
```html
This text is blue and larger.
```
Internal/Embedded Styles
Internal CSS is defined within a
Welcome to My Page
This paragraph is styled using internal CSS.
```
External Stylesheets
External stylesheets are the most recommended and widely used method for applying CSS. Styles are written in a separate .css file and then linked to the HTML document using the tag within the section. This approach promotes separation of concerns, making your code modular, easier to maintain, and allowing styles to be reused across multiple HTML pages.
Example (HTML file - index.html):
```html
My Styled Website
This content gets its style from an external stylesheet.
```
Example (CSS file - styles.css):
```css
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f4f4;
margin: 20px;
}
h1 {
color: #333;
text-align: center;
border-bottom: 2px solid #ccc;
padding-bottom: 10px;
}
p {
color: #555;
font-size: 16px;
line-height: 1.5;
}
.my-button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
}
.my-button:hover {
background-color: #0056b3;
}
```
Basic CSS Selectors
CSS selectors are patterns used to select the HTML elements you want to style. Mastering selectors is fundamental to effectively applying CSS.
Element Selectors
An element selector targets all instances of a specific HTML element.
Example:
```css
p {
color: green; / All paragraphs will be green /
}
h2 {
font-size: 24px; / All H2 headings will have a font size of 24px /
}
```
Class Selectors
A class selector targets elements that have a specific class attribute. Classes are highly versatile because you can apply the same class to multiple different elements, and an element can have multiple classes. Class selectors are denoted by a dot (.) followed by the class name.
Example (HTML):
```html
This text is important.
And so is this.
```
Example (CSS):
```css
.highlight {
background-color: yellow;
font-weight: bold;
}
```
ID Selectors
An ID selector targets a single, unique element that has a specific id attribute. The id attribute must be unique within an HTML document. ID selectors are denoted by a hash (#) followed by the ID name. While powerful, overuse of IDs for styling is often discouraged in favor of classes due to specificity and reusability.
Example (HTML):
```html
Website Title
```
Example (CSS):
```css
#main-header {
background-color: #333;
color: white;
padding: 20px;
}
```
Essential CSS Properties for Beginners
Once you understand how to select elements, the next step is to learn the properties you can apply to them. CSS has a vast array of properties, but a few core ones will cover most of your styling needs as a beginner.
Text Styling
Controlling the appearance of text is a fundamental aspect of web design.
color
Sets the color of the text. Can use named colors (e.g., red), hexadecimal codes (e.g., #FF0000), RGB values (e.g., rgb(255, 0, 0)), or HSL values (e.g., hsl(0, 100%, 50%)).
```css
p {
color: navy;
}
```
font-family
Specifies the font to be used. It's good practice to provide a "font stack" – a list of preferred fonts, with a generic family (like sans-serif or serif) as a fallback.
```css
body {
font-family: Arial, sans-serif;
}
h1 {
font-family: 'Times New Roman', serif;
}
```
font-size
Sets the size of the font. Can use pixels (px), em units (em), rem units (rem), or percentages (%). For accessibility and responsiveness, em or rem are often preferred over px.
```css
p {
font-size: 16px;
}
h2 {
font-size: 1.5em; / 1.5 times the parent's font size /
}
```
font-weight
Controls the boldness of the text. Common values include normal, bold, lighter, bolder, or numerical values from 100 to 900.
```css
strong {
font-weight: bold;
}
```
text-align
Aligns the text horizontally within its containing element. Values include left, right, center, and justify.
```css
h1 {
text-align: center;
}
```
line-height
Sets the height of each line of text. Often specified as a unitless number (e.g., 1.5) which is a multiple of the font size, or in px.
```css
p {
line-height: 1.6;
}
```
Box Model Properties
Every HTML element is essentially a rectangular box. The CSS box model describes how these boxes are structured, including their content, padding, border, and margin. Understanding the box model is crucial for layout and spacing.
width and height
Set the width and height of an element's content area.
```css
img {
width: 200px;
height: auto; / Maintain aspect ratio /
}
div {
width: 50%; / 50% of the parent's width /
}
```
padding
The space between the element's content and its border. Padding pushes content inwards. Can be specified for all sides (e.g., padding: 10px;), or individually (e.g., padding-top: 5px;, padding-right: 10px;, padding-bottom: 15px;, padding-left: 20px;), or using shorthand (e.g., padding: 10px 20px; for top/bottom and left/right, respectively).
```css
.card {
padding: 15px;
}
```
border
A line that goes around the padding and content. The border shorthand property combines width, style, and color.
```css
.button {
border: 2px solid #007bff;
}
```
margin
The space outside the element's border, separating it from other elements. Margin pushes elements away from each other. Like padding, it can be specified for all sides or individually. margin: auto; is commonly used for horizontal centering of block-level elements.
```css
p {
margin-bottom: 20px;
}
.container {
margin: 0 auto; / Centers the container horizontally /
width: 800px;
}
```
background-color and background-image
background-color sets the background color of an element.
background-image sets an image as the background.
```css
body {
background-color: #f0f0f0;
}
.hero-section {
background-image: url('images/hero.jpg');
background-size: cover; / Resize the background image to cover the entire container /
background-position: center; / Center the background image /
}
```
Basic Layout with CSS
Beyond individual element styling, CSS is indispensable for arranging elements on a page and creating responsive layouts that adapt to different screen sizes.
Display Property
The display property is one of the most fundamental for controlling how an element behaves in terms of layout.
Block-Level vs. Inline Elements
By default, HTML elements have either block or inline display properties.
- Block-level elements (e.g.,
div,p,h1,ul) always start on a new line and take up the full available width. You can set theirwidth,height,margin, andpadding. - Inline elements (e.g.,
span,a,img,strong) do not start on a new line and only take up as much width as their content requires. You generally cannot set theirwidthorheight(thoughpaddingand horizontalmargindo apply).
The display property allows you to change this default behavior.
display: block;: Makes an inline element behave like a block element.display: inline;: Makes a block element behave like an inline element.display: inline-block;: Allows an element to flow inline with other elements, but also allows you to set itswidth,height, and verticalmargin/padding. This is often used for creating grid-like layouts with older CSS techniques.display: none;: Hides an element completely, removing it from the document flow.
Example:
```css
.inline-block-example {
display: inline-block;
width: 150px;
height: 100px;
margin: 10px;
background-color: lightblue;
border: 1px solid blue;
}
```
Positioning Elements
The position property controls the type of positioning method used for an element. This is crucial for arranging elements outside the normal document flow.
static (Default)
Elements with position: static; are positioned according to the normal flow of the document. top, right, bottom, and left properties have no effect. This is the default value for all HTML elements.
relative
Elements with position: relative; are positioned according to the normal flow, but then offset relative to their own original position. The space they originally occupied in the layout remains reserved. top, right, bottom, and left properties will move the element from its normal position.
Example:
```css
.box {
position: relative;
top: 20px;
left: 30px;
}
```
absolute
Elements with position: absolute; are removed from the normal document flow and positioned relative to their nearest positioned ancestor (an ancestor with position other than static). If no such ancestor exists, it's positioned relative to the initial containing block (usually the element). Absolute positioned elements do not reserve space in the normal document flow, meaning other content will flow into their original space.
Example:
```html
```
fixed
Elements with position: fixed; are removed from the normal document flow and positioned relative to the browser window (viewport). They remain in the same position even when the page is scrolled. This is commonly used for navigation bars that stay visible at the top of the screen.
Example:
```css
.fixed-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
```
Introduction to Flexbox (Flexible Box Layout)
For modern web layouts, Flexbox is an incredibly powerful and widely used CSS module. It provides an efficient way to lay out, align, and distribute space among items in a container, even when their size is unknown or dynamic.
Flex Container and Flex Items
To use Flexbox, you define a parent element as a flex container by setting its display property to flex or inline-flex. Its direct children then become flex items.
```css
.flex-container {
display: flex;
/ Other flex properties go here /
}
```
Basic Flex Properties
flex-direction: Defines the direction of the main axis (the direction flex items are placed in the flex container). Values includerow(default),row-reverse,column,column-reverse.justify-content: Aligns flex items along the main axis. Values likeflex-start,flex-end,center,space-between,space-aroundare common.align-items: Aligns flex items along the cross axis (perpendicular to the main axis). Values includeflex-start,flex-end,center,baseline,stretch.
Example:
```html
```
```css
.flex-container {
display: flex;
flex-direction: row; / Items will lay out horizontally /
justify-content: center; / Items will be centered horizontally /
align-items: center; / Items will be centered vertically /
height: 200px; / Give container a height to demonstrate align-items /
border: 1px solid black;
}
.flex-item {
background-color: lightgreen;
padding: 20px;
margin: 10px;
}
```
Flexbox is a deep topic, but understanding these basic properties will allow you to create powerful and flexible layouts with minimal effort.
Bringing it All Together: Building Your First Webpage
Now that you have a grasp of HTML for structure and CSS for styling, it's time to put your knowledge into practice by creating a simple webpage. This will reinforce the concepts and show you how these two languages interact.
Setting Up Your Environment
All you need to start is a text editor and a web browser.
- Text Editor:
- For beginners, a simple text editor like Notepad (Windows), TextEdit (Mac - remember to save as plain text), or VS Code (highly recommended for its features) will work.
- Visual Studio Code (VS Code) is a free, open-source, and incredibly powerful code editor. Download it from
code.visualstudio.com. It offers syntax highlighting, auto-completion, and extensions that greatly enhance the coding experience.
- Web Browser:
- Any modern web browser (Chrome, Firefox, Edge, Safari) will render your HTML and CSS. You simply open your
.htmlfile directly in the browser to view your work.
Creating Your HTML Structure (index.html)
Create a new file named index.html in a folder on your computer.
```html
Welcome to My First Webpage!
Understanding HTML & CSS
This page demonstrates basic HTML structure and CSS styling. It's a stepping stone into the vast world of web development.
About This Project
We're learning to build web pages using the foundational technologies: HTML for content structure and CSS for visual presentation. This journey starts with understanding elements, attributes, selectors, and properties.
What You'll Achieve
- Create a basic HTML document.
- Apply styles using an external CSS file.
- Understand fundamental layout concepts.
Get in Touch
Feel free to connect with me. This is a placeholder for future interactive elements.
Email: beginner@example.com
```
Crafting Your Stylesheet (styles.css)
Create another file named styles.css in the same folder as your index.html file.
```css
/ General Body Styles /
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
/ Header Styles /
.main-header {
background-color: #333;
color: #fff;
padding: 1rem 0;
text-align: center;
position: sticky; / Makes header stick to the top /
top: 0;
z-index: 1000; / Ensures header is above other content /
}
.main-header h1 {
margin: 0;
font-size: 2.5em;
}
/ Navigation Styles /
nav ul {
list-style: none;
padding: 0;
margin: 0;
display: flex; / Use flexbox for horizontal navigation /
justify-content: center;
gap: 20px; / Space between nav items /
}
nav ul li a {
color: #fff;
text-decoration: none;
font-weight: bold;
padding: 0.5rem 1rem;
transition: background-color 0.3s ease; / Smooth hover effect /
}
nav ul li a:hover {
background-color: #555;
border-radius: 5px;
}
/ Main Content Section /
.content-section {
padding: 2rem;
max-width: 960px;
margin: 20px auto; / Center the content area /
background-color: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
border-radius: 8px;
}
section {
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px dashed #eee;
}
section:last-of-type {
border-bottom: none;
}
h2 {
color: #007bff;
border-bottom: 2px solid #007bff;
padding-bottom: 0.5rem;
margin-top: 0;
}
h3 {
color: #4CAF50;
margin-top: 1.5rem;
}
p {
margin-bottom: 1rem;
}
.responsive-image {
max-width: 100%; / Make image responsive /
height: auto; / Maintain aspect ratio /
display: block; / Remove extra space below image /
margin: 1.5rem 0;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
/ Footer Styles /
.main-footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 1rem 0;
margin-top: 2rem;
}
.main-footer p {
margin: 0;
font-size: 0.9em;
}
```
Viewing Your Page
Save both index.html and styles.css in the same folder.
Navigate to that folder on your computer and double-click index.html. It should open in your default web browser, displaying your styled webpage!
Experiment by changing values in styles.css (e.g., background-color, font-size) and then refreshing your browser to see the changes. Add new HTML elements and try to style them using the CSS properties you've learned. This hands-on practice is invaluable for solidifying your understanding.
Next Steps and Further Learning
Congratulations on building your first webpage! You've taken significant steps in understanding the fundamental building blocks of the web. This is just the beginning of a fascinating and rewarding journey. The world of web development is constantly evolving, but the core principles of HTML and CSS remain steadfast.
HTML5 Semantic Elements
Modern HTML (HTML5) introduced semantic elements that provide more meaning about the content they contain. Instead of using generic
,
, ,
,
,
, and
help both developers and search engines understand the structure and purpose of different parts of your page. Using them improves accessibility and SEO.
Responsive Web Design
The web is accessed on countless devices, from tiny smartwatches to massive desktop monitors. Responsive Web Design is the practice of building websites that adapt gracefully to different screen sizes and orientations. Key techniques include:
- Fluid Grids: Using relative units (like percentages) for widths instead of fixed pixels.
- Flexible Images: Using
max-width: 100%; height: auto;for images. - Media Queries: CSS rules that apply styles only when certain conditions (like screen width) are met. For example, you can hide a sidebar on small screens or change the layout of your navigation.
The CSS Grid Layout
While Flexbox is excellent for one-dimensional layouts (rows or columns), CSS Grid Layout is a powerful tool for two-dimensional layouts (rows and columns). It allows you to create complex, robust, and responsive page layouts with ease. Learning Grid alongside Flexbox will give you a comprehensive toolkit for almost any layout challenge.
Version Control with Git and GitHub
As you start working on larger projects, you'll want a way to track changes to your code, collaborate with others, and revert to previous versions if needed. Git is a version control system, and GitHub is a popular platform for hosting Git repositories. Learning these tools is a crucial skill for any developer.
JavaScript: Adding Interactivity
Once you're comfortable with HTML and CSS, the next logical step is to learn JavaScript. JavaScript is a programming language that allows you to add dynamic and interactive behavior to your webpages. It's what makes carousels slide, forms validate, buttons perform actions, and content update without a full page reload.
Continuous Learning
Web development is a field of continuous learning. Stay curious, experiment with new properties and techniques, and don't be afraid to break things and fix them. There are countless online resources, tutorials, documentation sites (like MDN Web Docs), and communities (like Stack Overflow) available to support your journey. Embrace the challenge, and enjoy the process of bringing your digital creations to life!
Related reading: How to Use AI to Build a Website · Website Speed: How to Test It and Make It Faster
Enda Storrie is a writer and the creator of Story Bible, the planning journal and app for writers, and Chain Story Online, a free collaborative storytelling platform.



