HTML

The Ultimate HTML Cheat Sheet For Beginners

Posted on Updated on

Below is a complete guide of HTML codes that you can copy and paste for use on your own blog or website. Although I like to insist on bloggers taking the time to learn how to write these codes and know what each part of them does, sometimes you need a code in a pinch!

 

Text Formatting

Headings

Defines an important heading in your text. You can use <h1> to <h6>, with the highest number resulting in the smallest font size.

<h1>Your important heading</h1>

Aligned Heading

Aligns your heading using a little bit of CSS. You can use “left”, “right”, or “justify” in place of “center” below:

<h1 style="text-align:center;">Your aligned heading</h1>

Paragraphs

Inserts a paragraph break. Defines each paragraph.

<p>Your paragraph here</p>

Aligned Paragraph

Aligns your paragraph using a little bit of CSS. You can use “left”, “right”, or “justify” in place of “center” below:

<p style="text-align:center">Your paragraph text is aligned</p>

Line Breaks

Line breaks are used instead of paragraphs, when you want to create a new line without starting a new paragraph.

The end of your sentence.<br />

Bold Text

Makes the weight of your font bold

<b>Your bold text</b>

Strong Text

Same look as bold text, but is semantic. Instead of it being simply a style, strong text shows how the text should be read or understood.

<strong>Your strong text</strong>

Italic Text

Makes your text italicized

<i>Your italic text</i>

Emphasized Text

Same look as Italic text in HTML, but is semantic. Specifies that the text should be emphasized when read.

<em>Your emphasized text</em>

Underlined Text

Underlines your text

<u>Your underlined text</u>

Strike-through

Places a line through your text to strike it out.

<s>Your text here</s>

Font Family

Changes the font of the text using a little CSS. You can change the font to any web safe font or Google web font:

<span style="font-family: Arial, Helvetica, sans-serif;">Your new font</span>

Font Size

Changes the size of the font using a little CSS. You can use px, em, or a percentage. Here is an example with px:

<span style="font-size:16px;">Your font in a new size</span>

Font Color

Changes the color of your font to any hex color value of your choice:

<span style="font-color:#030303;">Your new font color</span>

Highlighted Text

Highlights the text with a background color using a little CSS:

<span style="background-color:#C2F2CA">Your highlighted text</span>

Block Quotes

Useful when quoting someone or when you need a particular part of your text to stand out.

<blockquote>Your quoted text here</blockquote>

Links

Basic Text Link

Use to add a link to specific text or a word. Replace the http://www.yourlink.com with your own link:

<a href="http://www.yourlink.com">Your linked text</a>

Open Link in New Tab

Used to open the link in a new window or tab instead of in the same web page:

<a href="http://www.yourlink.com" target="_blank">Your linked text</a>

Link To An Email Address

Opens the user’s email program to quickly send an email to the address supplied. Replace the email address with your own:

<a href="mailto:you@youremailaddress.com">Your email address or link</a>

 Link To An Email Address With Subject Line

Useful if you want the email to have a specific subject when a user clicks your link. Use %20 in place of any spaces and replace the text with your own subject line:

<a href="mailto:you@youremailaddress.com?subject=Your%20Email%20Subject">Your email address or link</a>

Anchored (“Jump”) Link

For jumping to a particular part of a page with the click of a link. This happens in two parts. First, include the code below wherever you want the user to end up when they click the link, for example, at the top of the post. Name it something unique:

<a name="backtotop"></a>

Then, add the anchor to your link that the user will click on to jump to that section:

<a href="#backtotop">Back to top</a>

Images

Basic Image

Include an image in your post. Replace the image URL with your own URL. You will need to have this image uploaded somewhere online. Describing your image helps with SEO:

<img src="http://www.yoursite.com/yourimage.jpg" alt="describe this image"/>

Image Link

For adding a link to a certain image. Replace the image URL and link with your own:

<a href="http://www.yourlink.com"><img src="http://www.yoursite.com/yourimage.jpg" alt="describe this image"/></a>

Image Link Opens In New Window

<a href="http://www.yourlink.com" target="_blank"><img src="http://www.yoursite.com/yourimage.jpg" alt="describe this image"/></a>

Image Width and Height

You can change the width and height of the image if you need to, however it’s usually best to resize your image prior to adding it to your site. You can specify the width and height below for browser compatibility. Change the width and height values to those of your actual image:

<img src="http://www.yoursite.com/yourimage.jpg" alt="describe this image" width="450" height="600"/>

Align Image to Left or Right of Paragraph

If you want to place your image to the left or right of a paragraph, use the following code, replacing “left” with “right” if you like:

<img src="http://www.yoursite.com/yourimage.jpg" alt="describe this image" align="left"/>

Backgrounds

The following should be completed in your site’s main CSS file, or a dedicated CSS section of your website/blog editor. If you don’t have a CSS section or file, you can place these codes in between <style> and </style> tags in the <head> section of your website’s HTML, although it is recommended to have an external CSS file.

Page Background Color

Change the overall background of your website or blog with this code. Replace the color hex code with your own.

body {
background-color:#c3c3c3;
}

Repeating Background Image

For smaller backgrounds that you want tiled, or larger backgrounds that were made to be repeating, use this code and replace the image URL with your own. You will need to upload the image online first:

body {
background-image:url(http://www.yourwebsite.com/background-image.jpg); 
background-repeat:repeat;
}

Change the above red “repeat” if you want the image to only repeat vertically: repeat-y
Change the above red “repeat” if you want the image to only repeat horizontally: repeat-x

Non-Repeating Background Image

For background images that you want displayed only once (not repeated or tiled). Replace the image URL with your own.

body {
background-image:url(http://www.yourwebsite.com/background-image.jpg);
background-repeat:no-repeat;
}

Top Centered Non-Repeating Background Image

Center your background image on the page, at the top. Replace the image URL with your own.

body {
background-image:url(http://www.yourwebsite.com/background-image.jpg);
background-repeat:no-repeat;
background-position: top center;
}

Top Centered Vertical Repeating Background Image

Center your background image on the page, at the top. It will repeat vertically down the page. Replace the image URL with your own.

body {
background-image:url(http://www.yourwebsite.com/background-image.jpg);
background-repeat:repeat-y;
background-position: top center;
}

Lists

Ordered List

This will create a numbered list. Replace list elements with your own:

<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>

Unordered List With Bullets

This will create a list with bullets instead of numbers. Replace list elements with your own:

<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul>

Unordered List With Different Bullet Types

You can change the bullet type of any unordered list to circle, square, or disc (default):

<ul>
<li style="list-style-type:square">List item 1</li>
</ul>

Unordered List with Custom Image Bullet

If you want to use your own bullet image instead of the default ones, you can do that as well with a little CSS. Perhaps a star or a heart or check mark? You will need to create a small enough image and upload it somewhere online:

<ul style="list-style-image:url('http://yourimageurl.com/yourbullet.jpg')">
 <li>List item 1</li>
 <li>List item 2</li>
 <li>List item 3</li>
 </ul>

Special HTML Characters

Copyright symbol ©

&copy;

Less Than Symbol <

&lt;

Greater Than Symbol >

&gt;

Ampersand &

&amp;

Trademark Symbol ™

&trade;

Non-breaking Space

&nbsp;

Quotation Mark ”

&quot;

Registered Trademark ®

&reg;

Heart ♥

&hearts;

Euro sign €

&euro;

Left Arrow ←

&larr;

Right Arrow →

&rarr;

Up Arrow ↑

&uarr;

Down Arrow ↓

&darr;

Spade ♠

&spades;

Club ♣

&clubs;

Diamond ♦

&diams;

 

Advertisements

HTML Attributes

Posted on Updated on

Attributes provide additional information about HTML elements.


HTML Attributes

  • HTML elements can have attributes
  • Attributes provide additional information about an element
  • Attributes are always specified in the start tag
  • Attributes come in name/value pairs like: name=”value”

The lang Attribute

The document language can be declared in the tag.

The language is declared in the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines:

Example

<!DOCTYPE html>
<html lang=“en-US”>
<body><h1>My First Heading</h1><p>My first paragraph.</p>

</body>
</html>

The first two letters specify the language (en). If there is a dialect, use two more letters (US).


The title Attribute

HTML paragraphs are defined with the

tag.

In this example, the

element has a title attribute. The value of the attribute is “About Learnforweb“:

Example

<p title=“About Learnforweb”>
Learnforweb is a web developer’s site.
It provides tutorials and useful tricks covering
many aspects of Front-end Development,
including HTML, CSS, Bootstrap, JavaScript etc.
</p>
Note When you move the mouse over the element, the title will be displayed as a tooltip.

The href Attribute

HTML links are defined with the tag. The link address is specified in the href attribute:

Example

<a href=learnforweb.wordpress.com>This is a link</a>

You will learn more about links and the tag later in this tutorial.


Size Attributes

HTML images are defined with the tag.

The filename of the source (src), and the size of the image (width and height) are all provided as attributes:

Example

<img src=“code.jpg” width=“104” height=“142”>

The image size is specified in pixels: width=”104″ means 104 screen pixels wide.

You will learn more about images and the tag later in this tutorial.


The alt Attribute

The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed.

The value of the attribute can be read by “screen readers”. This way, someone “listening” to the webpage, i.e. a blind person, can “hear” the element.

Example

<img src=“Code.jpg” alt=“Coding” width=“104” height=“142”>

We Suggest: Always Use Lowercase Attributes

The HTML5 standard does not require lower case attribute names.

The title attribute can be written with upper or lower case like Title and/or TITLE.

W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.

Note Lower case is the most common. Lower case is easier to type.
At Learnforweb we always use lower case attribute names.

We Suggest: Always Quote Attribute Values

The HTML5 standard does not require quotes around attribute values.

The href attribute, demonstrated above, can be written as:

W3C recommends quotes in HTML4, and demands quotes for stricter document types like XHTML.

Sometimes it is necessary to use quotes. This will not display correctly, because it contains a space:

Example

<p title=About W3Schools>
Note Using quotes are the most common. Omitting quotes can produce errors.

Single or Double Quotes?

Double style quotes are the most common in HTML, but single style can also be used.

In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:

Example

<p title=‘John “ShotGun” Nelson’>

Or vice versa:

Example

<p title=“John ‘ShotGun’ Nelson”>

Chapter Summary

  • All HTML elements can have attributes
  • The HTML title attribute provides additional “tool-tip” information
  • The HTML href attribute provides address information for links
  • The HTML width and height attributes provide size information for images
  • The HTML alt attribute provides text for screen readers
  • At W3Schools we always use lowercase HTML attribute names
  • At W3Schools we always quote attributes with double quotes

HTML Attributes

Below is an alphabetical list of some attributes often used in HTML:

Attribute Description
alt Specifies an alternative text for an image
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element
title Specifies extra information about an element (displayed as a tool tip)
value Specifies the value (text content) for an input element.

HTML Elements

Posted on

HTML documents are made up by HTML elements.


HTML Elements

HTML elements are written with a start tag, with an end tag, with the content in between:

<tagname>content</tagname>

The HTML element is everything from the start tag to the end tag:

<p>My first HTML paragraph.</p>
Start tag Element content End tag
<h1> My First Heading </h1>
<p> My first paragraph. </p>
<br>
Note Some HTML elements do not have an end tag.

Nested HTML Elements

HTML elements can be nested (elements can contain elements).

All HTML documents consist of nested HTML elements.

This example contains 4 HTML elements:

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

HTML Example Explained

The <html> element defines the whole document.

It has a start tag <html> and an end tag </html>.

The element content is another HTML element (the <body> element).

<html>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

The <body> element defines the document body.

It has a start tag <body> and an end tag </body>.

The element content is two other HTML elements (<h1> and <p>).

<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>

The <h1> element defines a heading.

It has a start tag <h1> and an end tag </h1>.

The element content is: My First Heading.

<h1>My First Heading</h1>

The <p> element defines a paragraph.

It has a start tag <p> and an end tag </p>.

The element content is: My first paragraph.

<p>My first paragraph.</p>

Don’t Forget the End Tag

Some HTML elements will display correctly, even if you forget the end tag:

Example

<html>
<body>

<p>This is a paragraph
<p>This is a paragraph

</body>
</html>

The example above works in all browsers, because the closing tag is considered optional.

Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.


Empty HTML Elements

HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Empty elements can be “closed” in the opening tag like this: <br />.

HTML5 does not require empty elements to be closed. But if you want stricter validation, or you need to make your document readable by XML parsers, you should close all HTML elements.


HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>.

The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4, and demandslowercase for stricter document types like XHTML.

Note At Learnforweb we always use lowercase tags.

HTML Basic Examples

Posted on Updated on

Don’t worry if these examples use tags you have not learned.

You will learn them in the next chapters.


HTML Documents

All HTML documents must start with a type declaration:.

The HTML document itself begins with and ends with .

The visible part of the HTML document is between and .

Example

<!DOCTYPE html>
<html>
<body><h1>My First Heading</h1><p>My first paragraph.</p></body>
</html>


HTML Headings

HTML headings are defined with the

to

tags:

Example

<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>

HTML Paragraphs

HTML paragraphs are defined with the

tag:

Example

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

HTML Links

HTML links are defined with the tag:

Example

<a href=http://www.learnforweb.wordpress.com>This is a link</a>

The link address is specified in the href attribute.

Attributes are used to provide additional information about HTML elements.


HTML Images

HTML images are defined with the tag.

The source file (src), alternative text (alt), and size (width and height) are provided as attributes:

Example

<img src=“code.jpg” alt=“Coding” width=“104” height=“142”>
Note You will learn more about attributes in a later chapter.

HTML Editors

Posted on

Write HTML Using Notepad or TextEdit

HTML can be edited by using a professional HTML editor like:

  • Adobe Dreamweaver
  • Microsoft Expression Web
  • CoffeeCup HTML Editor

However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).

We believe using a simple text editor is a good way to learn HTML.

Follow the 4 steps below to create your first web page with Notepad.


Step 1: Open Notepad

To open Notepad in Windows 7 or earlier:

Click Start (bottom left on your screen). Click All Programs. Click Accessories. Click Notepad.

To open Notepad in Windows 8 or later:

Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad.


Step 2: Write Some HTML

Write or copy some HTML into Notepad.

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

Notepad


Step 3: Save the HTML Page

Save the file on your computer.

Select File > Save as in the Notepad menu.

Name the file “index.htm” or any other name ending with htm.

UTF-8 is the preferred encoding for HTML files.

ANSI encoding covers US and Western European characters only.

View in Browser

Note You can use either .htm or .html as file extension. There is no difference, it is up to you.

Step 4: View HTML Page in Your Browser

Open the saved HTML file in your favorite browser. The result will look much like this:

View in Browser

Note To open a file in a browser, double click on the file, or right-click, and choose open with.

 

HTML Introduction

Posted on

What is HTML?

HTML is a markup language for describing web documents (web pages).

  • HTML stands for Hyper Text Markup Language
  • A markup language is a set of markup tags
  • HTML documents are described by HTML tags
  • Each HTML tag describes different document content

HTML Example

A small HTML document:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>

Example Explained

  • The DOCTYPE declaration defines the document type to be HTML
  • The text between <html> and </html> describes an HTML document
  • The text between <head> and </head> provides information about the document
  • The text between <title> and </title> provides a title for the document
  • The text between <body> and </body> describes the visible page content
  • The text between <h1> and </h1> describes a heading
  • The text between <p> and </p> describes a paragraph

Using this description, a web browser can display a document with a heading and a paragraph.


HTML Tags

HTML tags are keywords (tag names) surrounded by angle brackets:

<tagname>content</tagname>
  • HTML tags normally come in pairs like <p> and </p>
  • The first tag in a pair is the start tag, the second tag is the end tag
  • The end tag is written like the start tag, but with a slash before the tag name
Note The start tag is often called the opening tag. The end tag is often called the closing tag.

Web Browsers

The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and display them.

The browser does not display the HTML tags, but uses them to determine how to display the document:

View in Browser


HTML Page Structure

Below is a visualization of an HTML page structure:

<html>

<head>

<title>Page title</title>

</head>

<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>

</html>

Note Only the <body> area (the white area) is displayed by the browser.

The <!DOCTYPE> Declaration

The <!DOCTYPE> declaration helps the browser to display a web page correctly.

There are different document types on the web.

To display a document correctly, the browser must know both type and version.

The doctype declaration is not case sensitive. All cases are acceptable:

<!DOCTYPE html>

<!DOCTYPE HTML>

<!doctype html>

<!Doctype Html>


Common Declarations

HTML5

<!DOCTYPE html>

HTML 4.01

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”&gt;

XHTML 1.0

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
Note All tutorials and examples use HTML5.

HTML Versions

Since the early days of the web, there have been many versions of HTML:

Version Year
HTML 1991
HTML 2.0 1995
HTML 3.2 1997
HTML 4.01 1999
XHTML 2000
HTML5 2014

 

HTML Tutorial

Posted on Updated on

HTML Tutorial
With HTML you can create your own Web site.
This tutorial teaches you everything about HTML.
HTML is easy to learn – You will enjoy it.