JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > CSS >

Styling input and submit buttons using CSS

Author:JIYIK Last Updated:2025/04/19 Views:

A submit button is a button used to submit data into a form. It is usually placed at the end of the form after all other fields are filled in. When you click the submit button, the form is transferred to the server for processing.

The syntax of the submit button is similar to other buttons in HTML, but the type should be submit. This article will teach you how to style input and submit buttons in HTML using CSS.


Creating a Submit Button in HTML

There are two ways to create a submit button. The first is to use the tag with type="submit"the attribute <input>.

This will create a button that, when clicked, will submit the form.

<button type='submit'>

The second method is to use <button>the <button> tag. This will create a button that can be customized using HTML.

<button>Tags can be used to submit forms or trigger JavaScript functions.

<input type="submit" value="Submit"/>

Creating an Input Button in HTML

An input button is a simple control that allows the user to click and select an action. You <input>create an input button using the element with the type attribute set to button.

<input type="button" value="Click me!">

When the user clicks a button, the action associated with the button is performed. In most cases, the action is defined in the form of a JavaScript event handler. For example, you can define a button that displays a warning message when clicked:

<input type="button" value="Click me!" onclick="alert('Hello world!')">

In addition to the value attribute, you can also set the label of the button using the label attribute.

For example

<input type="button" value="Click me!" label="Hello world!">

You can also use CSS to style the input button. For example, you can set the button's width, height, color, and so on.


Styling input and submit buttons using CSS

When it comes to styling your input and submit buttons with CSS, you’ll want to make sure they choose the same size, color scheme, and all other style attributes to keep your design consistent.

Styling input buttons with CSS

An input button is an essential element of any web page or application. It allows users to submit information or take an action and is styled using the browser's default styles. However, you can override the default styles using CSS.

There are several different ways to style input buttons using CSS. The most typical approach is to use the CSS pseudo-classes: hover , **:active**, and :focus . These pseudo-classes change the style of the button when the user hovers over it, clicks it, or gives it focus.

Another way to style input buttons is to use the CSS3 properties box-shadow and border-radius. These properties allow you to add a shadow around the button and make it rounded.

Finally, you can use the CSS3 property transform to scale, rotate, or skew a button. This can create exciting effects, such as making a button grow larger when the user hovers over it.

All of these methods can be used to create unique and stylish input buttons.

Styling the submit button with CSS

A method of styling your submit button using available CSS properties. This is an ideal way to give your button a unique look that matches the overall style of your website.

Another approach is to style the button container, which gives you more control over the overall appearance of the button. This can be useful if you want to add a background image or other elements to the button.

Code Sample

<!DOCTYPE html>
<html>
    <head>
        <style>
            input[type="submit"] {
                position: absolute;
                top: 65%;
                left: 25%;
                transform: translate(-50%, -50%);
                -ms-transform: translate(-50%, -50%);
                background-color: #f1f1f1;
                color: black;
                font-size: 16px;
                padding: 16px 30px;
                border: none;
                cursor: pointer;
                border-radius: 5px;
                text-align: center;
                border: 2px solid #4caf50; /* Green */
                box-shadow: 0 7px 16px 0 rgba(0, 0, 0, 0.4), 0 6px 21px 0 rgba(0, 0, 0, 0.19);
            }

            input[type="submit"]:hover {
                background-color: #4caf50; /* Green */
                color: white;
            }

            input[type="text"] {
                width: 40%;
                padding: 14px 30px;
                margin: 9px 0;
                box-sizing: border-box;
            }
            input[type="textarea"] {
                padding: 36px 40px;
            }
        </style>
    </head>

    <body>
        <h2>Styling form buttons</h2>
        <div class="form-center">
            <form action="#" method="post">
                Name <input type="text" placeholder="Full name" />
                <br />
                Email <input type="text" placeholder="Email address" />
                <br />
                Date <input type="text" placeholder="Date" />
                <input type="submit" value="Submit" />
            </form>
        </div>
    </body>
</html>

Summarize

Both submit buttons and input fields are elements; the difference is that input fields are used to indicate data entry, while submit buttons can be used to submit data to a form. Additionally, to make your buttons look aesthetically pleasing, border-radiusattributes can also be used to create visual effects.

For example, you can use it to make a button that looks like it's being pressed into the page when clicked, and do many more design tricks with CSS.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Overriding Bootstrap CSS

Publish Date:2025/04/19 Views:80 Category:CSS

This article introduces the famous CSS UI framework Bootstrap. We will discuss the process of overriding Bootstrap CSS with custom styles. Bootstrap Overview Using Bootstrap CSS makes it quicker and easier to create responsive websites than

Applying multiple transformations in CSS

Publish Date:2025/04/19 Views:143 Category:CSS

CSS transforms are a powerful but underutilized way to add animation effects to elements. However, it can be tricky to get the desired results when applying multiple transformations at once; for example, we want elements to transform in syn

Rotating text using CSS

Publish Date:2025/04/19 Views:152 Category:CSS

In this article, we will use CSS to rotate HTML text. Rotated text is commonly used in many languages, such as Chinese, Japanese, or Korean. Moreover, when designing a web page, developers may need to rotate the text to a certain degree to

Hide bullet points using CSS

Publish Date:2025/04/19 Views:163 Category:CSS

In this article, we will learn to hide the bullet points of a list in HTML. Developers can use HTML lists to display related items point by point. We can ol create ordered lists using the HTML tag and ul unordered lists using the HTML ul ta

覆盖 Bootstrap CSS

Publish Date:2023/04/28 Views:136 Category:CSS

本文介绍的是著名的 CSS UI 框架 Bootstrap。 我们将讨论使用自定义样式覆盖 Bootstrap CSS 的过程。

使用 CSS 制作带圆角的 HTML 表格

Publish Date:2023/04/28 Views:247 Category:CSS

这个简短的文章是关于在 HTML 页面上制作圆角表格的 CSS 样式。使用 CSS 制作带圆角的 HTML 表格 使图像、表格或 div 段的角变圆的属性是 border-radius。

CSS 设置轮廓 outline 的半径

Publish Date:2023/04/28 Views:141 Category:CSS

在本文中,用户将学习如何为 outline 属性设置圆角,与 border-radius 属性相同。 在这里,我们已经解释了将圆角应用于轮廓属性的不同方法。

使用 CSS 居中视频

Publish Date:2023/04/28 Views:272 Category:CSS

在本文中,用户将学习仅使用 CSS 将 <video> 元素居中。 我们已经在下面解释了使用 CSS 使视频居中的多种方法。

使用 CSS 居中内联块

Publish Date:2023/04/28 Views:123 Category:CSS

在本文中,我们将创建多个 HTML 元素并将其显示设置为 inline-block。 之后,我们将学习使用 display: inline-block 将所有元素居中。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial