Basic HTML Codes for Websites

Written by Web Hosting Expert

August 11, 2023
Basic HTML Codes for Websites

In today's digital age, having a basic understanding of HTML (Hypertext Markup Language) is essential for anyone aspiring to create a website. HTML forms the foundation of every web page, allowing developers to structure content and create interactive websites

In this article, we will introduce fundamental HTML codes to help you start building your own website. We will cover document structure, headings, paragraphs, links, images, lists, tables, and forms. Whether you are a beginner or want to refresh your HTML skills, this article will be a valuable guide.

What is HTML?

HTML, short for HyperText Markup Language, is a standardized markup language used for creating web pages. It provides tags to structure and layout content within a web document. HTML tags are enclosed in angle brackets (<>) and include an opening tag, content, and a closing tag. These tags instruct web browsers on how to display and interpret the content.



with the discount code



Importance of HTML

HTML is essential to the internet as it provides the structure, formatting, and functionality required to create web pages. Understanding HTML is the first step in web development, enabling individuals to build functional and visually appealing websites.

Structure and Organization

HTML provides a logical structure for web content. It allows developers to define headings, paragraphs, lists, and other elements, which not only enhance readability but also aid in search engine optimization (SEO).

Cross-Platform Compatibility

HTML ensures cross-platform compatibility, making web pages accessible across different devices and operating systems. It allows content to adapt to various screen sizes and resolutions, enabling responsive web design and ensuring a consistent user experience.

Hyperlinks and Navigation

HTML enables hyperlink creation for seamless navigation between web pages. Hyperlinks are vital for the interconnected nature of the internet allowing easy movement within and across websites. HTML's <a> tag makes it possible to link to external resources, internal pages, or specific page sections.

Media Integration

HTML supports the inclusion of multimedia elements, such as images, audio, and video, within web pages. By using HTML's <img>, <audio>, and <video> tags, developers can embed visual and auditory content directly into their websites, enhancing engagement and user experience.

Forms and User Interaction

HTML forms enable user interaction and data collection on websites. Forms allow users to input data, submit information, and interact with web applications. HTML provides elements like text fields, checkboxes, radio buttons, dropdown menus, and submit buttons, which are essential for creating interactive web pages.

Foundation for Web Technologies

HTML is the foundation for web technologies like CSS (Cascading Style Sheets) and JavaScript. CSS styles HTML elements, improving the visual presentation and layout of web pages, while JavaScript adds interactivity and dynamic functionality to HTML-based websites.

Basic HTML Structure

An HTML document follows a standard structure, consisting of several essential elements:

Basic HTML Structure

Doctype Declaration:

The doctype declaration (<!DOCTYPE html>) is placed at the very beginning of an HTML document. It informs the browser about the version of HTML being used, which is HTML5 in this case. This declaration ensures that the document is rendered correctly.


The <html> tag serves as the root element of an HTML document. It encompasses the entire content of the page and provides the base for all other elements.

Head Section:

The <head> section comes after the opening <html> tag and before the <body> tag. It contains meta information about the document, such as the page title, character encoding, CSS stylesheets, JavaScript files, and other metadata.

The content within the <head> section is not directly visible on the page but is crucial for search engines and browsers to understand and process the document correctly.

Title Tag:

The title tag is placed within the <head> section. It defines the title of the web page, which is displayed on the browser's title bar or in search engine results. The text enclosed within the <title> tags is a concise description of the page's content and should accurately represent its purpose.

Body Section:

The <body> tag contains the visible content of the web page. It includes text, images, links, and interactive elements like forms or buttons. Everything between the opening <body> tag and the closing </body> tag is considered the body content.

Here is a basic HTML template that illustrates the standard structure: html

<!DOCTYPE html>
 <head> <title>Page Title</title> 
 <h1>Welcome to My Website</h1> 
<p>This is the content of my web page.</p>
 <a href="">Visit Example</a> 
<!-- Additional elements and content go here →

In the example above, the <title> tag sets the page title, and within the <body> section, we have a heading <h1>, a paragraph <p>, and a link <a> to the website "". This template is a starting point, and you can add more elements and content within the <body> section to build your web page.

Remember, this is a basic representation of the HTML structure. As you progress in web development, you will encounter more complex elements and tags to enhance the functionality and design of your web pages.

Essential HTML Tags

Heading Tags

Heading tags, from <h1> to <h6>, are used to define headings and subheadings in a web page. They play a crucial role in organizing and structuring content. The higher the number in the heading tag, the less significant the heading is. Here is an example:


<h1>This is the Main Heading</h1>

<h2>This is a Subheading</h2>

Heading tags not only provide visual hierarchy but also contribute to search engine optimization (SEO) by signalling the importance of content to search engines

Paragraph and Break Tags

The <p> tag is used to define paragraphs of text. It is a block-level element that creates a new paragraph. Here is an example:


<p>This is a paragraph of text.</p>

<p>Another paragraph of text.</p>

If you want to create a line break within a paragraph, you can use the <br> tag, which is an empty element. Here is an example:


<p>This is the first line.<br>
 This is the second line.</p>

Anchor Tags

The <a> tag is used to create hyperlinks. It allows you to link to other web pages, documents, or specific parts of a page. The href attribute specifies the URL of the destination. Here is an example:


<a href="">Visit Example</a>

You can also use the target attribute to control how the link opens. For example, target="_blank" opens the link in a new browser tab:


<a href="" target="_blank">Visit Example</a>

Image Tags

The <img> tag is used to embed images in a web page. The src attribute specifies the image source (file URL or path). The alt attribute provides alternative text that describes the image for accessibility purposes. Here is an example:


<img src="image.jpg" alt="Description of the image" title="Image Title">

You can also use the title attribute to provide additional information about the image when the user hovers over it: html

<img src="image.jpg" alt="Image Description" title="Additional Information">

List Tags

HTML provides two types of lists: unordered lists (<ul>) and ordered lists (<ol>). The <li> tag is used to define individual list items within these lists. Here is an example:


 <li>Item 1</li> 
<li>Item 2</li>

Table Tags

Tables are used to present data in a structured format. The <table> tag creates the table, while the <tr> tag defines table rows. Within each row, we use the <td> tag to define table cells. The <th> tag is used for table headers. Here is an example:


 <th>Header 1</th>
 <th>Header 2</th>
<td>Data 1</td>
 <td>Data 2</td>

Div and Span Tags

The <div> tag is used for grouping elements together and applying styles or JavaScript to them. The <span> tag is used for inline styling or targeting specific parts of the text. Here is an example:


<div> <p>This is a group of elements.</p>
 <span style="color: blue;">This text is styled differently.</span> </div>

Form Tags

The <form> tag is used to create a web form. The <input> tag represents various input types such as text fields, checkboxes, radio buttons, etc. The <textarea> tag is used for multi-line text input, and the <button> tag represents a clickable button. Here is an example.


<form action="/submit-form" method="POST"> 
<label for="name">Name:</label>
 <input type="text" id="name" name="name" required>
 <label for="email">Email:</label>
 <input type="email" id="email" name="email" required>
<textarea id="message" name="message" rows="4" cols="50" required></textarea> <br> 
<button type="submit">Submit</button> 

These examples demonstrate the usage of the essential HTML tags discussed.



with the discount code


Save Now

Styling HTML with CSS

Styling HTML with CSS

CSS (Cascading Style Sheets) is a stylesheet language that defines the visual appearance and layout of HTML elements on a web page. It provides a powerful and flexible way to customize the presentation of web content. CSS works by applying rules and styles to HTML elements, allowing developers to control aspects such as colours, fonts, sizes, spacing, and positioning.

Different Methods of Adding CSS Styles to HTML Documents

Inline CSS, Internal CSS, and External CSS are three different methods of adding CSS styles to HTML documents:

Inline CSS:

Inline CSS involves adding style rules directly to HTML elements using the style attribute. It provides a quick way to apply specific styles to individual elements. Here is an example:


<p style="color: blue; font-size: 18px;">This is a paragraph with inline CSS.</p> In the above example, the style attribute is added to the <p> tag to set the colour to blue and the font size to 18 pixels.

Internal CSS:

Internal CSS is defined within the <style> tag, which is placed in the <head> section of an HTML document. It allows you to apply styles to multiple elements within the same HTML file. Here's an example:


{ color: blue;
 font-size: 18px; 
<p>This is a paragraph with internal CSS.</p>

External CSS:

External CSS allows you to keep your styles separate from your HTML document. Styles are defined in an external CSS file and linked to the HTML document using the <link> tag. This approach is recommended for larger projects as it promotes better organization and reusability of styles. Here is an example:


<link rel="stylesheet" type="text/css" href="styles.css">
 <body> <p>This is a paragraph with external CSS.</p> 

CSS file (styles.css):


{ color: blue;
 font-size: 18px; 

Using external CSS files allows for easy maintenance and modification of styles across multiple web pages. It also promotes consistency and separation of concerns between HTML structure and visual presentation.

Best Practices in HTML Coding

Following coding standards is essential for clean, maintainable, and efficient HTML code. Consistent and well-structured code improves readability, makes collaboration easier, and minimizes errors. Some best practices to consider include:

Indentation and Formatting: Use consistent indentation and proper formatting to enhance code readability. This helps you and other developers understand the structure of the HTML document more easily.

Naming Conventions: Use descriptive and meaningful names for HTML elements, classes, and IDs. This improves code clarity and makes it easier to understand the purpose of each element.

Avoid Inline Styles: Inline styles should be used sparingly. Instead, consider using external or internal CSS to separate styling from HTML structure, promoting better organization and maintainability.

Semantic HTML: Utilize semantic HTML elements (e.g., <header>, <nav>, <section>, <article>, <footer>) to convey the structure and meaning of the content. Semantic HTML improves accessibility, search engine optimization, and overall code quality.

Consistent Tag Naming: Stick to lowercase tag names to ensure consistency and compatibility across different browsers and versions.

Importance of Comments

Comments in HTML serve as helpful documentation, providing context, explanations, and reminders for yourself and other developers. They can be used to:

Describe Intent: Comment on the purpose of specific sections or elements within the HTML code to help others understand your intentions.

Temporary Disabling: Use comments to temporarily disable certain code blocks without removing them entirely. This allows for easier debugging or testing.

Collaboration and Documentation: Comments facilitate collaboration by providing insights into the code's logic, potential issues, or workarounds. They also serve as a form of documentation, making it easier to maintain and update the codebase in the future.

To add comments in HTML, use the <!-- Comment goes here --> syntax. The content within the comment tags will not be rendered by the browser.

Proper Tag Closure

Properly closing HTML tags is crucial for maintaining the integrity of the document structure. Each opening tag should have a corresponding closing tag. For example:


 <p>This is a paragraph.</p> 

For self-closing tags, such as <img> or <br>, the closing slash is optional in HTML5. However, it is good practice to include it for consistency and compatibility across different versions of HTML.

Incorrect tag closure can lead to unexpected rendering issues and can make the HTML difficult to debug. Use proper indentation and visually check your code to ensure all tags are correctly closed.

By adhering to proper tag closure, you ensure that the HTML document maintains its structure, making it easier to read, maintain, and debug.



with the discount code


Grab the Discount


Learning HTML is best reinforced through practice. Encourage yourself to apply the knowledge gained in this article by building small web pages or projects. Experiment with different HTML tags and CSS styles to create visually appealing and well-structured web content. Remember to refer to online resources, documentation, and practice-based tutorials to further refine your skills.

By practising and exploring advanced topics, you will gradually become more proficient in web development and be able to create engaging and interactive websites.

Happy coding!

Frequently Asked Questions

What are the different types of lists that can be created using HTML?

HTML provides two main types of lists: unordered lists (<ul>) and ordered lists (<ol>). Unordered lists display list items with bullet points, while ordered lists display list items with numbers or letters. Additionally, nested lists can be created by placing a list inside another list.

How do I use div and span tags in HTML?

The <div> and <span> tags are used for grouping elements and applying styles. The <div> tag is a block-level element used for grouping sections of content, while the <span> tag is an inline element used for grouping smaller portions of text or elements. You can apply CSS classes or IDs to style or manipulate these elements.

How can I add multimedia content, such as audio and video, in my HTML page?

To add multimedia content in HTML, you can use the <audio> and <video> tags. The src attribute specifies the URL of the audio or video file, while additional attributes control playback options, appearance, and accessibility. Here is an example of adding a video: html

<video src="video.mp4" controls></video>

What are HTML entities and how are they used?

HTML entities are special character codes used to represent characters that have special meanings in HTML. For example, the &lt; entity represents the less-than symbol (<), and & represents the ampersand (&). Entities are useful when you need to display reserved characters, symbols, or characters with special encoding. For example: html

<p>&lt; represents less than</p>
 <p>&amp; represents ampersand</p>
Jivo Live Chat