- CSS Tutorial
- CSS Introduction
- CSS Syntax
- CSS Comments
- CSS Selectors
- CSS Fonts
- CSS Colors
- CSS Backgrounds
- CSS Box Model
- CSS Borders
- CSS Margins
- CSS Padding
- CSS Text
- CSS Images
- CSS Links
- CSS Lists
- CSS Tables
- CSS Outline
- CSS Icons
- CSS Display
- CSS max-witdh
- CSS Position
- CSS z-index
- CSS Overflow
- CSS Float
- CSS Align
- CSS Opacity
- CSS Navigation Bar
- CSS Dropdowns
- CSS Forms
- CSS Units
- CSS !important
- CSS Specificity
- CSS Combinators
- CSS inline-block
- CSS Hover
- CSS Cursors
- CSS Selectors
- CSS Type Selector
- CSS Class Selector
- CSS ID Selector
- CSS Attribute Selector
- CSS Pseudo-class Selector
- CSS Pseudo-element Selector
- CSS Universal Selector
- CSS Advanced
- CSS Text Formatting
- CSS Gradients
- CSS Shadow
- CSS Rounded Corners
- CSS Text Effects
- CSS 2D Transform
- CSS 3D Transform
- CSS Border Images
- CSS Inherit
- CSS Transitions
- CSS Animations
- CSS Box Sizing
- CSS Tooltip
- CSS Masking
- CSS Pagination
- CSS Styling Images
- CSS object-fit
- CSS object-position
- CSS Buttons
- CSS Multiple Columns
- CSS Variables
- CSS Flexbox
- CSS Grid
- CSS Media Queries
CSS Forms
In CSS, forms refer to the visual styling of HTML form elements like input fields, textareas, and buttons. Here are some common techniques for styling forms:
Input Fields:
- Use the
widthproperty to set the width of input fields. - Apply padding and margin to create space inside and around the input fields.
- Customize borders and add rounded corners using the
borderandborder-radiusproperties. - Change background color and text color with
background-colorandcolor. - Remove the default blue outline on focus using
outline: none.
Textareas:
- Use the
resizeproperty to prevent textareas from being resized. - Example form:
HTML
<form action="/submit" method="post">
<input type="text" name="name" placeholder="Your name">
<input type="password" name="password" placeholder="Your password">
<input type="submit" value="Submit">
</form>Here’s a simple example of a styled form using CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Basic form styling */
form {
max-width: 300px;
margin: 0 auto;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type="submit"] {
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<form action="/submit" method="post">
<input type="text" name="name" placeholder="Your name">
<input type="password" name="password" placeholder="Your password">
<input type="submit" value="Submit">
</form>
</body>
</html>In this example:
- The form is centered with
max-widthandmargin. - Input fields have consistent padding, border, and rounded corners.
- The submit button changes color on hover.