TimesCoding

Learn, Practice, and Excel with our Coding Tutorials!

How to Create a Stylish and Modern HTML Select Field Using CSS

June 2, 2024 2 Min read CSS HTML
html select

Creating a modern and stylish HTML “Select” field involves using CSS to enhance the default styling. Here’s an example of how you can achieve this:

HTML Code for Select field

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stylish Select Field</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="custom-select-container">
        <label for="fruit-select" class="select-title">Choose Your Favorite Fruit</label>
        <select id="fruit-select" class="custom-select">
            <option value="" disabled selected>Select a fruit</option>
            <option value="apple">Apple</option>
            <option value="banana">Banana</option>
            <option value="cherry">Cherry</option>
            <option value="date">Date</option>
            <option value="elderberry">Elderberry</option>
        </select>
    </div>
</body>
</html>

CSS Code for Select field

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.custom-select-container {
    position: relative;
    width: 250px;
    text-align: center;
}

.select-title {
    font-size: 18px;
    margin-bottom: 10px;
    display: block;
}

.custom-select {
    width: 100%;
    padding: 10px 20px;
    font-size: 18px;
    border: 3px solid #007bff; /* Bold border */
    background-color: #e0f7fa; /* Suitable background color */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="gray" class="bi bi-chevron-down" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
    cursor: pointer;
    color: #333;
}

.custom-select option {
    padding: 10px;
    font-size: 18px;
    color: #000;
}

.custom-select option:checked {
    background-color: #007bff;
    color: #fff;
}

.custom-select:focus {
    border-color: #0056b3;
    outline: none;
}

.custom-select option[value="apple"] {
    color: red;
}

.custom-select option[value="banana"] {
    color: yellow;
}

.custom-select option[value="cherry"] {
    color: darkred;
}

.custom-select option[value="date"] {
    color: brown;
}

.custom-select option[value="elderberry"] {
    color: purple;
}

/* Style for the down arrow */
.custom-select::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 15px;
    width: 10px;
    height: 10px;
    background-color: #007bff;
    clip-path: polygon(100% 0%, 0 0%, 50% 100%);
    transform: translateY(-50%);
    pointer-events: none;
}

This CSS will create a modern, stylish select field that looks good and is easy to interact with with web forms.

Tags

  1. “How to customize HTML select field with CSS”
  2. “Stylish select dropdown menu tutorial”
  3. “Modern CSS techniques for HTML select boxes”
  4. “Creating attractive select fields using CSS”
  5. “Step-by-step guide to styling HTML select elements”

Related Post:
Trendy Website Color Combinations for 2024 − Here are some trending color combinations to consider for your website, including header, footer, sidebar, and content section colors with codes: 1. Balanced Brights: 2..
Create a Stylish Analog Watch with HTML, CSS, and JavaScript − Creating a stylish analog watch using HTML, CSS, and JavaScript involves simulating the appearance and movement of clock hands. We’ll build a simple analog clock.
How to Create a Stylish Digital Watch with HTML, CSS, and JavaScript − Creating a digital watch similar to an Apple Watch using HTML, CSS, and JavaScript involves several steps. We’ll build a simple, functional digital clock that.
Creating a Stylish and Responsive Bootstrap Menu with Colorful Toggle Icon − Below is a simple responsive Bootstrap 5 template that you can use as a starting point for your project. This template includes a stylish &.
Responsive Web Design with CSS: A Short Tutorial − Responsive web design is a crucial aspect of modern web development. It ensures that your website looks and functions well on a variety of devices,.
How to Create a Modern Stylish Accordion with Arrows Using Only HTML and CSS − This modern and stylish accordion is created using only HTML and CSS, featuring smooth transitions and interactive arrows that change direction upon expansion. It’s perfect.
Modern and Stylish Button with Gradient and Hover Effects − This modern and stylish button features a vibrant gradient background that seamlessly transitions on hover, coupled with a subtle box shadow for added depth. Its.
Creating a Modern Responsive Menu with HTML & CSS Only − Learn how to design a stylish and modern website header section and responsive menu using just HTML and CSS, with a responsive menu that toggles.
Design a Modern and Stylish Login Form using HTML and CSS − This is a modern and stylish login form using HTML and CSS, featuring 3D effects, colorful fields, and a button. The “Not registered? Create an.
Creating a Modern Button with Stylish Hover Effects Using CSS − This is a modern and stylish button with a simple hover effect using CSS. The button has a bold border & the border color will.
How to Create a Colorful Tic-Tac-Toe Game with HTML, CSS and JavaScript − Here’s a colorful Tic-Tac-Toe game implemented using HTML, CSS, and JavaScript only. The game includes a restart button, winner message, and special effects for the.
Pure CSS Custom Modern and Stylish Checkboxes − Creating a custom modern and stylish checkboxes using pure CSS can enhance the visual appeal of your web forms. Here’s a simple and elegant checkboxes.