Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
HTML

HTML: Create Interactive Forms for User Input

- 05.07.26 - ErcanOPAK

📝 Forms = User Input

Web apps need user input. HTML forms collect data. Text, choices, files — all in one form.

📝 Form Elements

<form action="/submit" method="POST">
    <!-- Text input -->
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" placeholder="Enter name" required>

    <!-- Email input -->
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" placeholder="email@example.com">

    <!-- Password input -->
    <label for="password">Password:</label>
    <input type="password" id="password" name="password">

    <!-- Number input -->
    <label for="age">Age:</label>
    <input type="number" id="age" name="age" min="1" max="120">

    <!-- Textarea -->
    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="4" cols="50"></textarea>

    <!-- Select dropdown -->
    <label for="country">Country:</label>
    <select id="country" name="country">
        <option value="">Select a country</option>
        <option value="us">United States</option>
        <option value="uk">United Kingdom</option>
        <option value="ca">Canada</option>
    </select>

    <!-- Radio buttons -->
    <fieldset>
        <legend>Gender:</legend>
        <input type="radio" id="male" name="gender" value="male">
        <label for="male">Male</label>
        <input type="radio" id="female" name="gender" value="female">
        <label for="female">Female</label>
        <input type="radio" id="other" name="gender" value="other">
        <label for="other">Other</label>
    </fieldset>

    <!-- Checkboxes -->
    <fieldset>
        <legend>Interests:</legend>
        <input type="checkbox" id="sports" name="interests" value="sports">
        <label for="sports">Sports</label>
        <input type="checkbox" id="music" name="interests" value="music">
        <label for="music">Music</label>
        <input type="checkbox" id="reading" name="interests" value="reading">
        <label for="reading">Reading</label>
    </fieldset>

    <!-- File upload -->
    <label for="file">Upload file:</label>
    <input type="file" id="file" name="file" accept=".jpg,.png,.pdf">

    <!-- Date input -->
    <label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday">

    <!-- Range slider -->
    <label for="rating">Rating:</label>
    <input type="range" id="rating" name="rating" min="1" max="5" value="3">

    <!-- Submit button -->
    <input type="submit" value="Submit">
    
    <!-- Reset button -->
    <input type="reset" value="Reset">
    
    <!-- Button -->
    <button type="button" onclick="alert('Clicked!')">Click Me</button>
</form>

🎯 Form Attributes

<form
    action="/submit"          <!-- Where to send -->
    method="POST"             <!-- GET or POST -->
    enctype="multipart/form-data" <!-- For file uploads -->
    autocomplete="on"         <!-- Browser autocomplete -->
    novalidate                  <!-- Disable HTML5 validation -->
    target="_blank"          <!-- Where to open result -->
>

<input
    type="text"
    name="username"
    value="John"
    placeholder="Enter username"
    required                <!-- Required field -->
    readonly               <!-- Read only -->
    disabled               <!-- Disabled -->
    maxlength="20"        <!-- Max characters -->
    min="1"               <!-- Min value -->
    max="100"             <!-- Max value -->
    pattern="[A-Za-z]+"   <!-- Regex pattern -->
    autofocus              <!-- Auto focus -->
>

💡 Best Practices

  • Use labels for accessibility
  • Group related fields with fieldset
  • Use appropriate input types
  • Validate on client and server
  • Sanitize user input on server

“Forms collect user data. Text, choices, files — all in one. Essential for interactive web apps.”

— Web Developer

Related posts:

HTML5: Speed Up Your LCP with Native loading='lazy'

required Attribute Is NOT Validation

Search text through Divs in Javascript

Post Views: 3

Post navigation

CSS: Master Flexbox for Modern Layouts
JavaScript: Use Promises for Better Async Handling

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com