# HTML

### Tags

* Normal Tag
  * Every HTML element has one opening and one closing tag, In between that if you write anything it will be visible in the browser.
  * Like in this example \<h1> \</h1>, \<h1> This is referd to openning tag but \</h1> This is refered to closing tag
* Self Closing Tag
  * Some HTML elements don't have a closing tag that closes in their opening tag
  * Link in this example \<input /> this tag is self-closing

### Structure of HTML

Html Document (The file which has a .html extension, e.g index.html) contains some predefined structure

<pre class="language-html"><code class="lang-html">&#x3C;!DOCTYPE html>
&#x3C;html>
<strong>    &#x3C;head>
</strong><strong>        &#x3C;title>Dymmy Page&#x3C;/title>
</strong><strong>        &#x3C;meta name="description" content="This is render when we search in google" />    
</strong><strong>    &#x3C;/head>
</strong><strong>    &#x3C;body>
</strong><strong>        &#x3C;!--
</strong><strong>        This is a comment it won't render in the browser
</strong><strong>        and inside the body whatever we write it will show in the browser
</strong><strong>        -->
</strong><strong>    &#x3C;/body>
</strong>&#x3C;/html>
</code></pre>

In the above code, we have a few tags, below I have discussed why we have to create this structure for every HTML

* \<!DOCTYPE html>
  * This is used as a 'declaration'. It isn't a tag. It is used to tell the browser how to render the page, which means how to show that page you have written in the code.
  * The browser doesn't understand different HTML versions, there are fewer tags in an older version of HTML like in HTML 4.1, the way we write in the above example the browser will understand it's an HTML5 document and it will render the same in every browser as you expect.
* The \<html> tag is used to tell the browser it is the entire document. It isn't necessary but it is an industry standard.
* \<head>
  * This is used to store information about the webpage, there are some predefined tags to show different things.
  * We will discuss these later about those but for now, we will understand two tags
  * title: Which are used to store the title of any site which is visible in two places One is in the tab of the browser and another is in the google search (In the example two this violet color youtube test is the title)
  * meta for all the information related to the webpage
    * In the second example, we use meta with name description for the Text written in gray

<div align="left"><figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2FWe51GYQrhiF2j90GHmvf%2F2022-08-30%2020_30_25-HTML%20-%20Front%20End%20Notes.png?alt=media&#x26;token=b7384d4b-1571-43e8-a56a-4850d12ace5c" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2FBZ6N4AzNget5VYZwTEZ6%2F2022-08-30%2020_34_04-youtube%20-%20Google%20Search.png?alt=media&#x26;token=278ca33b-d899-4e9b-92c0-43dd914e9d80" alt=""><figcaption></figcaption></figure></div>

The body is the content that will be visible in the browser

### Different HTML tags and their use

<table><thead><tr><th width="180">Tag Name</th><th>Purpose</th></tr></thead><tbody><tr><td>&#x3C;html>&#x3C;/html></td><td>Start and end of document</td></tr><tr><td>&#x3C;h1>&#x3C;/h1></td><td>Leargest Heading, There are 6 type of heading tag h1, h2, ... h6</td></tr><tr><td>&#x3C;p>&#x3C;/p></td><td>paragraph tag, use to show text in normal size.</td></tr><tr><td>&#x3C;br/></td><td>Use to add like break. Using this will put everything after this tag in the next line</td></tr><tr><td>&#x3C;strike>&#x3C;/strike></td><td>Text with strike through like <del>This is strike through text</del></td></tr><tr><td>&#x3C;b>&#x3C;/b> OR &#x3C;strong>&#x3C;/strong></td><td>Both b and strong use to bold the text. Like <strong>Bold Text</strong></td></tr><tr><td>&#x3C;i>&#x3C;/i></td><td>i tag is used to make the text italic. Like <em>Italic Text</em></td></tr><tr><td>&#x3C;u>&#x3C;/u></td><td>This is used to underline text.</td></tr><tr><td>&#x3C;table>&#x3C;/table></td><td>table tag is used to create table this contains multiple tags to create a proper table Like td, tr, thead, tbody. We will have different section for that to uderstand properly.</td></tr><tr><td>&#x3C;img /></td><td>This is used to show images. it has multiple <a href="#undefined">attributes</a>, like src with the value of the image file. alt for alternative text if the image isn't visible.</td></tr><tr><td>&#x3C;form>&#x3C;form></td><td>This is used to create a form, it also contains multiple <a href="#undefined">attribute</a>, That will help to set the behavior of the form.</td></tr><tr><td>&#x3C;input /></td><td>This is used to take input from the user. <a href="#undefined">visit here for more</a></td></tr><tr><td>&#x3C;button>&#x3C;/button></td><td>To show a clickable button</td></tr><tr><td>&#x3C;a href="website link" /></td><td>This is used to add link to another page or website</td></tr><tr><td>&#x3C;!-- Comment between this -- ></td><td>We use this way to comment between HTML, comment doesn't reflect in the browser.</td></tr></tbody></table>

### Attributes & Content\`

There are different sections of a tag

<figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2F8nv4rM6V2lBLOyRPQzTg%2F2022-08-30%2020_57_56-Microsoft%20Whiteboard.png?alt=media&#x26;token=22ebcb64-11d5-487f-afe1-baf1f126d3f8" alt=""><figcaption></figcaption></figure>

In the above example, I have show different section of a tag

* In the **red line,**  we have the tag name which is p in this example
* in the **green underline,** we have the attribute name which is  class in the example
* in the **Yellow Line,** we have the value for that attribute, Like here infoParagraph is the value of class attribute
  * We write attribute as **attributeName="attributeValue"**
* In the **Blue Line,** we have the content for the tag.
* We use attributes for different purposes, every tag has its own set of predefined attributes.

### Input

**\<input type="type of the different input" />** eg. ***\<input type="text" />***

<table><thead><tr><th width="237">type</th><th>purpose</th></tr></thead><tbody><tr><td>text</td><td>To take Text Input</td></tr><tr><td>password</td><td>To take password input, no character in the input box will be visible everything will look like *.</td></tr><tr><td>email</td><td>takes only email input</td></tr><tr><td>radio</td><td>To select only one between options</td></tr><tr><td>checkbox</td><td>use to select multiple options.</td></tr><tr><td>button</td><td>To show a clickable button, but we need to pass value attribute to give content to the button</td></tr><tr><td>submit</td><td>Submit is also like type button but it can submit a form, this is mainly used to submit a form.</td></tr><tr><td>file</td><td>This helps us to take file input</td></tr><tr><td>number</td><td>Takes only number as input</td></tr><tr><td>range</td><td>it wil give us a slider to take a range between two values, we can pass min and max as attribute</td></tr><tr><td>search</td><td>this will help us to create a seach box, it looks similar like text box, but when we write something it will show a 'x' button to clear the text </td></tr><tr><td>tel</td><td>to take phone number as input</td></tr><tr><td>time </td><td>this will help us to take time input</td></tr><tr><td>reset </td><td>just like a button helps to clear a form</td></tr><tr><td>url</td><td>to take url inputs</td></tr></tbody></table>

Here is the example of different tags and how it looks

<div><figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2F36DqixfWB9zapmtj4VDC%2F2022-08-30%2021_29_42-cool-surf-uf0ymf%20-%20CodeSandbox.png?alt=media&#x26;token=71c7036e-6666-47da-9547-4a73881693c5" alt=""><figcaption><p>Click to zoom</p></figcaption></figure> <figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2Fuz62448spkh7QlxOs6tE%2F2022-08-30%2021_30_22-cool-surf-uf0ymf%20-%20CodeSandbox.png?alt=media&#x26;token=bfb32fdd-ac06-4c53-a757-9022da31659b" alt=""><figcaption><p>Click to zoom</p></figcaption></figure></div>

### How to link CSS?

Create a CSS (Cascade Style Sheet) file in your project folder. And then use link tag as the child of head tag of your HTML document.

\<link rel="stylesheet" href="./styles.css" />

In the above line the

* The link is the tag to link other files
* the rel attribute is used to show the type of file you linked
* and the href to link the file, we pass the path of the file as the href's value.

In the example in the project folder where you html is present we have created a style.css file. And then we linked that with this tag.

### How to style any tag?

This is a two-step process after linking your css file to your html.

The first one is to name the tag, or some kind of identifier to find that tag. We have two kind of identifier

1. class: we can pass class in any tag as an attribute and the value of that class is the name of that tag.
2. id: As class we can also pass id as an argument of any tag and pass value as the name of that tag. **BUT the key difference between id and class is we can use same class name for multiple tags, but not for id, id must be unique.**

```html
<body>
    <!-- In this tag I have showed you how you can write class
      we can add multiple classs of one tag separated by space( )
      Most preferable way to write class name is the secondClass way
      -->
    <div class='first-class secondClass'>
    </div>
    <!-- we can use class and id both in one tag -->
    <div class="testClass" id="testID">
    </div>
</body>
```

The Second step is, using that identifier in css

In the css, we have three way to point a element of a HTML, in the below example I will show it how

```html
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <p>Hello Partner</p>
    <div class="firstBox">
      first box
    </div>
    <div id="secondBox">
      second box
    </div>
  </body>
</html>

```

Here below I have attached the CSS of the above HTML, read the comment's to understand what happened.

```css
/* All the example here is for the above HTML */

/* We use no prefix before the tag name
 to point the tag, and change css of that tag 
 This isn't good as it will select all p in the whole HTML
 */
p {
  color: red;
}

/*
We use a dot (.) as prefix of the class to identify as 
a class, this is best way to point a tag
*/
.firstBox {
  color: blue;
}

/* We use the pound symbol (#) as to identify as Id
This is also a good way to point a tag, only down side and also upside
is that you can only style a single tag with this but in terms of class
you can use that class to similar like tag, where you want the style
and the style will be applied
*/

#secondBox {
  color: purple;
}

```

Here you can see the output of that HTML

<figure><img src="https://1359291869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPghbmX2IFFVtLvp60rvl%2Fuploads%2FF9juLFTL1oCY92A1Eqew%2F2022-09-11%2020_22_58-Html%20code%20editor%20(forked)%20-%20CodeSandbox.png?alt=media&#x26;token=4cdc026d-4024-4ecc-b2e7-9eaec6287336" alt=""><figcaption><p>OUTPUT with style</p></figcaption></figure>
