ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Learning HTML For Beginners

Updated on April 19, 2016

Step 1: Get a source code editor

This tutorial is going to take you through the process of using HTML to create a website. First you want to begin by using a source code editor like Sublime Text 3 or Notepad ++ to write your code in.

I personally like to use Sublime Text 3. Here is a link to the page where you can download it:

https://www.sublimetext.com/3


Step 2: Set up your index file

Create a new folder on your desktop and save it as new_website. Open your code editor and create a new file, save your new file as index.html in your new_website folder. By saving as index.html you are creating a default page that the web server will recognize as the top level page to open.

*Quick Tip* Once you save the file as html, you can simply type html and Tab and the file setup will automatically complete.

If you are not using Sublime Text 3 you can type this code manually.

This is what you should see:


HTML Auto Complete

Source

Step 3: Using tags

As you can see the content is contained using tags. There must be an opening tag and a closing tag in order for it to work properly. A closing tag looks like this />, it is just a back slash and closing bracket. There are some special tags that are self containing and don't require a closing tag such as the line break tag <br>. The <br> tag creates a new line of text beneath the existing line of text.

The placement of the tags on the page are very important as they perform in a hierarchy sequence. For example the most important tag is first, the <!DOCTYPE html> tag is telling the browser what kind of document it is defined as, in this case it is an html file. The <!DOCTYPE html> is followed by an opening and closing html tag which contains all of the content for the page.

The next tag which is processed by the browser is the head tag which has the information that is placed in the head of the document. Here you will find the title tag, script tag, link tag, meta tag and a few others.

Thar part of the document where you want to place your content is in the body. In the video example I have provided, you will see that I started with the heading tags. The heading tags come in different default sizes however these can be customized and styled to your liking. It is general practice to style a page using the largest heading <h1> to the smallest heading <h5> as you place headings into your document.




Video Tutorial HTML For Beginners

Step 4: Using proper syntax

You want to make sure that the html is written properly in lower case letters. The <!DOCTYPE html> tag however is always written in upper case letters. It is very important to nest your elements properly so that your parent tag contains the content and closes after the content. In the image below you will notice that the section tag is containing the <ul> tag and the list elements are contained within the <ul> tag.

HTML Syntax

Step 5: Using Classes

One of the ways to target a specific section of code is by giving it a class. A class can give the code a certain type of style which is targeted in the css. To write a class for a section of code you begin with the div tag. You then need to give a name to your class, it is best to name it something that will make sense. For example if you want to contain a section within a purple box you can type <div class="purplebox"></div>. The closing div tag would be placed at the very end of the paragraph or where you would like to close the section. By calling the class something specific you will make it easier to understand your own code when you want to edit.

Once your class is applied in your index file, you will then have to create a css file or open a style tag in the head of the document to style your class. A class is called in the stylesheet with a . in front of it. For example our purple box class will be written as .purplebox{}. It must have opening and closing curly brackets. The styles that you would like to apply to the class are contained within the curly brackets followed by a semi colon;

You can apply classes to html elements like the p tag, img tag, heading tags etc. When you give a class to the p tag it will only affect the text of that section. The same applies with heading tags.




Using an id selector

Another way to select a portion of code that you would like to style is by containing it with an id selector. The id selector can be applied using a div tag and is used in the same way that a class is used with the exception that the id name cannot be used more than once. It must have a unique name to target a specific element.

Another difference between the classes and id's is that id's are targeted in css with a # hashtag rather than a period. Just like with classes, you want to give an id a name that is suitable for what it's being used for.

The styles in the browser

Adding margins and padding

As you can see, the text inside of the box is squished to the very edge of the box. If you would like for the text to have some more space in between so that it looks nicer you will have to give it padding. Padding is space that is applied either to the top, right, bottom or left of the element.

For the purple box I will apply 20px of padding to all of the sides by simply coding it as padding: 20px; This targets all of the sides of the box. You also have the option to target only certain sides, for example you can say padding-top:20px; and it will only affect the top portion between the text and the box.


Adding padding and margin

The padding and margin in the browser

Spacing your elements

When you want to add padding to a p tag, you want to target the p in the css because by adding padding to the box, the box will become larger. If you would like to add margin to the box simply apply the margin to box class. As you can see the difference between the first box that didn't have padding versus after the padding styles were applied, it looks much nicer and appealing for the user.

If you would like to center align the boxes you can apply margin: auto 0 to the box class.

Follow the links below for more information

Thanks for checking out my tutorial for beginner HTML, if you would like some more information make sure to check out the following links to help you out with your coding.

Code on!

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.