0% found this document useful (0 votes)
7 views12 pages

HTML Basics: Tags, Attributes, and Styles

wow

Uploaded by

dvsking54
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

HTML Basics: Tags, Attributes, and Styles

wow

Uploaded by

dvsking54
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

HTML

INTRODUCTION
SYNTAX:
<TAG>Content</TAG> //Always close tags after entering the content. Closing tags have the same
name but with “ / ” symbol at the start.

BASIC TAGS:
<!DOCTYPE html> //This tag implies that this is a html file

<html></html> //tag used to declare the start of a html document

<head></head> //tag used to provide more information about the


document(metadata). This info is separate from the contents of
the actual webpage.

<title>Parthib</title> //tag used to provide a title for the


webpage (is visible as the name of the browser tab)

<body></body> //tag used to define the start of the content


visible in the webpage

<h1>Parthib</h1> //tag used to define a heading


There are different variations of this tag ranging from 1-6:
<h2>Sayak</h2>
<h3>Numan</h3>
<h4>Rohit</h4>
<h5>Prince</h5>
<h6>Rishi</h6>
HTML
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nisl ligula, placerat eget dui
quis, laoreet volutpat velit. Praesent imperdiet libero in viverra convallis. Curabitur interdum mi at
magna faucibus, in elementum nisl pellentesque. Curabitur malesuada id leo at lacinia. Sed quis
pellentesque nisi, vel hendrerit erat. Aliquam laoreet odio id magna auctor ultrices. Nam pretium
elementum turpis nec consectetur. Curabitur vel eros lacus.</p>

//The <p></p> tag is used to write paragraphs of text onto a


webpage

example of a paragraph with a heading using <h> and <p> tags

Code:
HTML
ATTRIBUTES
SYNTAX:
<Tag AttributeName = “Value”>Content</Tag> //Make sure to always use Quotation marks for
Values.

WHAT ARE THEY USED FOR?

Attributes are used to provide and modify additional information about content in certain tags, for
example:

Changing the color of text in a paragraph using <p style=”color:red”><\p> (style attribute)

EMPTY TAGS
SYNTAX:
<Tag> //Empty tags don’t need closing tags in order to function

EXAMPLES:
<hr> //this tag is used to draw ending lines or separators
HTML
<br> //this tag is used to go to the next line while writing a paragraph

STYLES
The style attribute can be used to add styles to content in a tag, such as color(Name, RGB, SRGB),
font, size, and more

//This is a CSS attribute and uses CSS values so styles need to be separated by “;” within the
attribute.

EXAMPLES:
1. We can change the background colour of a heading using <h1 style=”background-color:
yellow”></h1>
HTML

2. We can change the font size of a paragraph using <p style=”font-size:50px”></p>

3. We can change the alignment of text in a paragraph using <p style=”text-align:center”></p>


HTML

FINAL:

CODE:
HTML
FORMATTING ELEMENTS
TAGS:
<b></b> //tags used to make text bold

<i></i> //tags used to make text italics

<mark></mark> //tags used to highlight text

<small></small> //tags used to make text smaller

<del></del> //tags used to slash through text

<abbr title=””></abbr> //tags used to define abbreviations. These mostly include the title attribute
to define these abbreviations.

COMMENTS:
<!—content-->

These are used to write information related to the code but don’t affect the webpage.

HYPERLINKS
SYNTAX:
<a href=”[Link] me</a>

These are used to direct the viewer to a different page, image and websites. URLS can be both
Absolute (Web links) and Relative (local address)

EXAMPLE:
CLICK/TAP ME

Click/tap on the above hyperlink for some fun.

ATTRIBUTE:
You can use the “target” attribute to provide additional information on how these links will behave

Some of the values are:

 _self - Default. Opens the document in the same window/tab as it was clicked
 _blank - Opens the document in a new window or tab
 _parent - Opens the document in the parent frame
 _top - Opens the document in the full body of the window
HTML
IMAGES
SYNTAX:
<img src=”image source” alt=”image name”> //Empty tag so it does not require an ending tag

This is used to insert images into a webpage.

ATTRIBUTES:
src – Image source

alt – Image name

style values:

width – adjust the width of the image

height – adjust the height of the image

EXAMPLE:

CODE:
HTML
FAVICON
This is the icon that is displayed on the tab beside the title

SYNTAX:
<link rel="icon" type="image/x-icon" href="/images/[Link]"> //This should be within <head> tag

The href url can be absolute and relative

EXAMPLE:
To put [Link] as our favicon

We put it in our root directory and then use:

<link rel="icon" type="image/x-icon" href="[Link] ">

Resulting in:
HTML
TABLES:
Create a table of data

SYNTAX:
<table> //initiate table

<tr> //Create a table row

<th></th> //display table header

<th></th>

<th></th>

</tr>

<tr>

<td></td> //display table column

<td></td>

<td></td>

</tr>

</table>

LISTS
Create a list of data

SYNTAX:
An unordered HTML list:

<ul> //initiate list


<li> </li> //list element
<li> </li>
<li> </li>
</ul>

An ordered HTML list:

<ol>
<li> </li>
<li> </li>
<li> </li>
</ol>
HTML
EXAMPLES:

DIV
Creates a new block with its own properties

SYNTAX:
<div></div>

EXPLANATION:
HTML
In the above website, each one of the blue boxes is a DIV. The website needs to be a collection of
DIVs for ease of styling and adding more elements.

DIVS can be nested within each other too.

Common questions

Powered by AI

Empty tags in HTML do not require a closing tag, which distinguishes them from most HTML tags that enclose content and therefore, must be closed with a corresponding closing tag . For example, the <br> tag used to create a line break and the <img> tag used to insert images are empty tags and do not need a closing tag. In contrast, tags like <p></p> for paragraphs and <h1></h1> for headings must have both opening and closing tags . This distinction simplifies the use of empty elements, as they do not contain any content and serve more functional purposes like line breaks or inserting images without the need for paired tags.

HTML attributes are instrumental in creating responsive and dynamic web pages by allowing developers to specify additional properties and behaviors for HTML elements. Attributes like 'style' enable inline CSS styling for quick customization of elements' appearance, which is essential for responsiveness across different device screens . The 'src' and 'alt' attributes within <img> tags determine the image source and description, ensuring that images are loaded efficiently and are accessible to users with disabilities . Attributes such as 'href' and 'target' for hyperlinks control navigation flow and how content is loaded, impacting both user experience and page interactivity. Thus, attributes provide the necessary parameters to refine and adapt elements dynamically .

HTML attributes are used to provide additional information and modify elements on a webpage. The 'style' attribute can change the appearance by setting CSS properties such as text color, font size, and alignment. For example, the inline style <p style="color:red"> will change the paragraph text color to red . The 'href' attribute in <a> tags specifies the URL for hyperlinks, while the 'target' attribute controls how links open (e.g., '_blank' opens in a new tab). For images, 'src' sets the image source and 'alt' provides alternative text . These attributes offer flexibility in how elements are presented and interacted with on a webpage.

HTML comments, denoted by <!-- content -->, are crucial for documenting code and providing explanations without affecting the webpage's display . Proper use of comments enhances code readability and maintenance, particularly in collaborative environments where multiple developers might work on the same project. Comments can clarify the purpose of certain code sections, note remaining tasks, or explain complex algorithms, thus reducing misunderstandings and facilitating smoother collaboration and debugging processes . However, excessive or outdated comments can lead to confusion, so they should be used judiciously and maintained accurately.

HTML tables are constructed using the <table>, <tr>, <th>, and <td> tags. <table> initiates the table, <tr> defines a table row, while <th> and <td> are used for headers and data cells respectively . This structure allows for organized data presentation in rows and columns, making tables ideal for displaying structured information like schedules, pricing lists, or comparison charts. Tables enhance readability and enable users to quickly understand relationships between data points, which is particularly useful in scientific, financial, and business contexts .

HTML lists, including ordered (<ol>) and unordered (<ul>) lists, provide a semantic way to present information that is inherently visual and hierarchical . Lists structure content logically, aiding comprehension for users and improving accessibility. Screen readers announce lists and list items in a way that conveys their structure, enhancing the user experience for visually impaired users. By semantically marking up groups of related items, lists also improve SEO, as search engines better understand content relationships and context. These benefits highlight the importance of using lists correctly to promote both accessibility and effective information retrieval .

Hyperlinks in HTML are structured using the <a> tag with the 'href' attribute to specify the destination URL. For improved accessibility and user experience, using descriptive anchor text within the <a> tag helps users understand the link's purpose without needing additional context . Attributes like 'target' can be used to control link behavior, such as '_blank' for opening links in new tabs, which can enhance user experience by preserving the current page context . Proper use of these techniques ensures that navigation is intuitive, accessible, and effective across different user needs and preferences.

The <div> element is immensely flexible and is used to create new blocks of content with their own properties, making it indispensable for complex web layouts . By providing a way to group elements and apply CSS styles, <div> enables developers to manage layout and design consistently. It allows for nesting, meaning <div>s can be placed within each other to structure webpage sections hierarchically. This capability is crucial for modular design, where styles can be applied globally or individually, thus streamlining updates and maintenance. Moreover, dividing content into logical blocks can improve code readability and facilitate the application of responsive design techniques .

The <head> section of an HTML document contains metadata and information that is not directly visible on the webpage. This includes elements like <title>, which sets the page's title in the browser tab, and links to stylesheets or scripts . The <body> section, in contrast, contains the actual content that users see and interact with, such as text, images, and other media . Together, these sections structure the web document, with the <head> ensuring proper integration and functionality of external resources and the <body> organizing the visible content.

Different heading levels in HTML, ranging from <h1> to <h6>, serve to establish a hierarchical structure within a webpage, aiding both visual organization and accessibility. <h1> is typically used for main titles, while subsequent levels are used for subheadings (<h2>, <h3>, etc.), allowing users and screen readers to understand content structure intuitively . Proper use of headings is crucial for Search Engine Optimization (SEO) as it helps search engines parse and index content meaningfully, enhancing discoverability. For individuals using assistive technologies, such as screen readers, well-structured headings improve navigation and understanding, thus enhancing accessibility .

You might also like