Table of Contents
✅ Basic HTML structure
? Corresponding CSS style (responsive design)
? Key design points description
? Tips (advanced suggestions)
Home Web Front-end CSS Tutorial css form layout example

css form layout example

Jul 25, 2025 am 04:31 AM
css form layout

The form layout adopts a responsive design and is suitable for multiple devices; 1. Use semantic HTML structures, including name, email, phone and message fields; 2. CSS settings centered containers, rounded borders and background colors to improve visual effects; 3. Each form item is arranged vertically, the label is bold and the associated input boxes are enhanced to enhance accessibility; 4. The input box and text field are 100% wide, the inner margins are uniform, and blue shadows are displayed when focusing; 5. The submit button is designed with full width green, hovering to dark green, improving interactive feedback; 6. Reduce spacing and fonts on a small screen through media queries; 7. Scalable to use flex layout to implement side-by-side input; 8. It is recommended to add JavaScript verification and error styles to enhance functions. The overall structure is simple and practical, and can be directly integrated into the project and end with a complete sentence.

css form layout example

Creating a beautiful and well-structured CSS form layout is a common requirement in web development. Below is a practical, responsive form layout example suitable for login, registration, or contact form scenarios.

css form layout example

✅ Basic HTML structure

 <form class="form-container">
  <h2>Contact Form</h2>

  <div class="form-group">
    <label for="name">name</label>
    <input type="text" id="name" name="name" required>
  </div>

  <div class="form-group">
    <label for="email">Email</label>
    <input type="email" id="email" name="email" required>
  </div>

  <div class="form-group">
    <label for="phone">Tel</label>
    <input type="tel" id="phone" name="phone">
  </div>

  <div class="form-group">
    <label for="message">Leave a message</label>
    <textarea id="message" name="message" rows="4"></textarea>
  </div>

  <button type="submit">Submit</button>
</form>

? Corresponding CSS style (responsive design)

 .form-container {
  max-width: 500px;
  margin: 40px auto;
  padding: 30px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #f9f9f9;
  font-family: Arial, sans-serif;
}

.form-container h2 {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: #555;
  font-weight: bold;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 16px;
  box-sizing: border-box; /* Make sure padding does not affect the width*/
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #4d90fe;
  box-shadow: 0 0 5px rgba(77, 144, 254, 0.3);
}

button[type="submit"] {
  width: 100%;
  padding: 12px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  margin-top: 10px;
}

button[type="submit"]:hover {
  background-color: #45a049;
}

/* Responsive: Adjust spacing on small screen*/
@media (max-width: 480px) {
  .form-container {
    padding: 20px;
    margin: 20px;
  }

  .form-group label {
    font-size: 14px;
  }
}

? Key design points description

  • box-sizing: border-box : Make sure padding and border do not increase the total width of the element.
  • width: 100% : Let the input box adapt to the container width to improve the responsive experience.
  • focus style optimization : Enhance accessibility and let users know the fields of the current operation.
  • Mobile adaptation : adjust spacing and fonts on small screens through media queries.
  • Semantic tags : Use <label> and associate for and id to improve accessibility and user experience.

? Tips (advanced suggestions)

  • Error status styles (such as red borders) can be added with JavaScript verification.
  • Use grid or flexbox to implement multiple column layouts (such as name phone side by side):
 .form-row {
  display: flex;
  gap: 15px;
}

.form-row .form-group {
  flex: 1;
}

Then in HTML:

 <div class="form-row">
  <div class="form-group">
    <label for="name">name</label>
    <input type="text" id="name" name="name">
  </div>
  <div class="form-group">
    <label for="phone">Tel</label>
    <input type="tel" id="phone" name="phone">
  </div>
</div>

Basically that's it. This form is simple and modern, compatible with most devices, and can be used directly in actual projects. It can be adapted to different topics with a slight modification.

css form layout example

The above is the detailed content of css form layout example. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1545
276
How to use the filter property in CSS How to use the filter property in CSS Aug 11, 2025 pm 05:29 PM

TheCSSfilterpropertyallowsvisualeffectslikeblur,brightness,andgrayscaletobeapplieddirectlytoHTMLelements.1)Usethesyntaxfilter:filter-function(value)toapplyeffects.2)Combinemultiplefilterswithspaceseparation,e.g.,blur(2px)brightness(70%).3)Commonfunct

How to use CSS selectors effectively How to use CSS selectors effectively Aug 11, 2025 am 11:12 AM

When using CSS selectors, low-specific selectors should be used first to avoid excessive limitations; 1. Understand the specificity level and use them reasonably in the order of type, class, and ID; 2. Use multi-purpose class names to improve reusability and maintainability; 3. Use attributes and pseudo-class selectors to avoid performance problems; 4. Keep the selector short and clear scope; 5. Use BEM and other naming specifications to improve structural clarity; 6. Avoid the abuse of tag selectors and:nth-child, and give priority to the use of tool classes or modular CSS to ensure that the style is controllable for a long time.

How to create a vertical line with CSS How to create a vertical line with CSS Aug 11, 2025 pm 12:49 PM

Use a div with border to quickly create vertical lines, and define styles and heights by setting border-left and height; 2. Use ::before or ::after pseudo-elements to add vertical lines without additional HTML tags, suitable for decorative separation; 3. In Flexbox layout, by setting the width and background color of the divider class, adaptive vertical dividers between elastic containers can be achieved; 4. In CSSGrid, insert vertical lines as independent columns (such as autowidth columns) into grid layout, which is suitable for responsive design; the most appropriate method should be selected according to the specific layout needs to ensure that the structure is simple and easy to maintain.

How to create a dotted border in CSS How to create a dotted border in CSS Aug 15, 2025 am 04:56 AM

Use CSS to create dotted borders, just set the border attribute to dotted. For example, "border:3pxdotted#000" can add a 3-pixel-wide black dot border to the element. By adjusting the border-width, the size of the point can be changed. The wider borders produce larger points. You can set dotted borders for a certain side, such as "border-top:2pxdottedred". Dotted borders are suitable for block-level elements such as div and input. They are often used in focus states or editable areas to improve accessibility. Pay attention to color contrast. At the same time, different from dashed's short-line style, dotted presents a circular dot shape. This feature is widely used in all mainstream browsers.

How to change the list style in CSS How to change the list style in CSS Aug 17, 2025 am 10:04 AM

To change the CSS list style, first use list-style-type to change the bullet or numbering style. 1. Use list-style-type to set the bullet of ul to disc, circle or square, and the number of ol is decimal, lower-alpha, upper-alpha, lower-roman or upper-roman. 2. Remove the tag completely with list-style:none. 3. Use list-style-image:url('bullet.png') to replace it with a custom image. 4. Use list-style-position:in

How to create a responsive testimonial slider with CSS How to create a responsive testimonial slider with CSS Aug 12, 2025 am 09:42 AM

It is feasible to create a responsive automatic carousel slider with pure CSS, just combine HTML structure, Flexbox layout, and CSS animation. 2. First build a semantic HTML container containing multiple recommendation terms, each .item contains reference content and author information. 3. Use the parent container to set display:flex, width:300% (three slides) and apply overflow:hidden to achieve horizontal arrangement. 4. Use @keyframes to define a translateX transformation from 0% to -100%, and combine animation: scroll15slinearinfinite to achieve seamless automatic scrolling. 5. Add media

How to create a responsive hero section with CSS How to create a responsive hero section with CSS Aug 11, 2025 am 11:28 AM

Useaflexiblecontainerwithheight:100vhormin-heightandbackground-size:covertoensuretheherosectionfillstheviewportwhilemaintainingimageaspectratio.2.PlacecenteredcontentusingFlexboxorplace-items:centerinCSSGridforverticalandhorizontalalignment.3.Maketex

How to change the cursor in CSS How to change the cursor in CSS Aug 16, 2025 am 05:00 AM

Usebuilt-incursortypeslikepointer,help,ornot-allowedtoprovideimmediatevisualfeedbackfordifferentinteractiveelements.2.ApplycustomcursorimageswiththecursorpropertyusingaURL,optionallyspecifyingahotspotandalwaysincludingafallbacklikeautoorpointer.3.Fol

See all articles