HTML Forms and Css
HTML Forms and Css
7:- <form>tag
The <form> tag is used to add HTML forms to the web page for user input. Forms are used to
pass the data submitted by the user to the server. The data is sent when pressing the "Submit"
button. If there isn’t such button, the information is sent when the "Enter" key is pressed.
Syntax
The <form> tag comes in pairs. The content is written between the opening (<form>) and closing
(</form>) tags.
The <form> element contains other HTML tags, which define the input method of data:
Example of <form>tag:-
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<form action="server-script-url-here" method="GET or POST" >
<label for="fname">Name</label>
<input type="text" name="FirstName" id="fname" value="Mary"/><br/><br/>
<label for="lname">Surname</label>
<input type="text" name="LastName"id="lname"
value="Thomson"/><br/><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<h1>Form example</h1>
<form action="server-script-url-here" method="GET or POST" >
<textarea rows="3" cols="30" placeholder="Type some text
here"></textarea><br/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
HTML Input Types
Here are the different input types you can use in HTML:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">
4) <input type="reset"> defines a reset button that will reset all form values to their default values
Radio buttons let a user select ONLY ONE of a limited number of choices:
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
9) The <input type="color"> is used for input fields that should contain a color.
Depending on browser support, a color picker can show up in the input field.
10) The <input type="date"> is used for input fields that should contain a date.
Depending on browser support, a date picker can show up in the input field.
Examples:-
<html>
<body>
<h2>Text field</h2>
<form action="/action_page.php">
</form>
<p>Note that the form itself is not visible.</p>
</body>
</html>
Output:-
Text field
First name:
Last name:
DHTML:-
DHTML stands for Dynamic HTML, it is totally different from HTML. ... The DHTML is based on the
properties of the HTML, javascript, CSS, and DOM (Document Object Model which is used to access
individual elements of a document) which helps in making dynamic content. It is the combination of
HTML, CSS, JS, and DOM.
The DOM presents HTML as a tree-structure (a node tree), with elements, attributes, and text:
CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
CSS Syntax:-
Each declaration includes a CSS property name and a value, separated by a colon.
A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly
braces.
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled with CSS.</p> </body> </html>
--------------------------------------------------------------------------------------------------------------------
OUTPUT :-
Hello World!
-------------------------------------------------------------------------------------------------------------------
Example Explained
p is a selector in CSS (it points to the HTML element you want to style: <p>).
color is a property, and red is the property value
text-align is a property, and center is the property value