HTML 按钮标签允许使用 HTML 文档在网页上创建活动按钮控件。这个元素在 body 标记内声明。为什么我们需要一个按钮元素?通常,当用户访问网页时,他最常见的行为是单击网站上的某个位置,从而转到下一个 URL 页面。为此,Button 元素无法单独完成;它是由表单操作创建的,其中 Web 表单有一个默认的提交按钮单击。
按钮是使用
语法:
与其他 HTML 标签一样,即使按钮标签也有开始和结束标签,并且按钮类型是使用属性定义的。
<button> // some stuff like content / image </button>
HTML 按钮标签的属性
没有使用特殊属性,因为它们没有任何必需的属性;相反,它们被用作具有 type=” 属性的普通按钮。 “甚至这个元素也是使用 CSS 设计的,其属性可以改变按钮标签中的变化。这些属性是 CSS 字体系列、字体粗细、文本装饰和字体样式。背景颜色等着色属性和文本溢出和文本缩进等布局属性。
S.no | Attribute Name | Description | Example |
1 | autofocus | It is considered a Boolean attribute. | |
2 | disabled | Making a button non-clickable. | |
3 | Form | It Creates a form | |
4 | formaction | It specifies the current location for submitting the form data. | |
5 | formnovalidate | It appears in gray and gives non-validation features. | |
6 | Formmethod | It specifies the methods while referring to the next web page(get the post of HTTP methods) | |
7 | formtarget | It specifies the target path for the server response when a form action is done. | |
8 | formenctype | It has been used when a form is submitted to the webserver for the response; it activates the type of content used. | |
8 | name | It specifies the button name used in the form element, which is used by form inputs. | |
9 | type | It specifies the type of button being used. It has three default values submit, reset, and text. | |
10 | value | It gives an initial value when a button is used along with the form data | |
11 | tabindex | It specifies the tab key and the order does the preference. | |
12 | onclick | When a button is pressed, it runs a small javascript code behind it. |
Examples to Implement in HTML Button Tag
Below are examples of implementing an HTML Button Tag:
Example #1
Code:
<title> HTML button tag Example</title> <h2 id="HTML-button-tag-Example">HTML button tag Example </h2>
Output:
Example #2
Code:
<h3> <center> Example using CSS </center> <h3> Normal Class <button type="button">Add to the First class</button> <hr> Economic Class <button type="button" style="color: pink;"><b> Book Economic Class </b></button> <hr> Bussiness class <button type="button" style="color: orange;"><b> Book Bussiness Class </b></button> <hr> Departure <button type="button" style="font: bold 12px Open Sans;">Norway </button><br> </h3> </h3>
Output:
Example #3
With CSS: Here, we have used padding and margin property. Here are some ways to look at the page better. To create a button with rounded corners, use border-radius.
Code:
<style> body { color: #000; height: 90vh; background: linear-gradient(-90deg, #a1c3d1 0%, #c48b9e 100%) no-repeat; text-align: center; } input { width: 280px; display: block; margin: 2rem auto; border: 3px solid #fbc7ff; padding: 7px; background: transparent; border-radius: 25px; outline: none; } ::placeholder { color: #00ced1; } .btn { background:#96f905; border: none; height: 3rem; border-radius: 20px; width: 220px; display: block; color: #96f905; outline: none; margin: 2rem auto; } </style> <h1 id="HTML-Form-action-Using-Button">HTML Form action Using Button</h1>
Output:
Example #4
The below example shows how to use the attribute autofocus with button element; in an example, when a page Loads, it focuses on the first HTML control.
Code:
<title> Button Demo <button>autofocus Attribute </button> </title> <h1 style="color: blue;"> EDUCBA Web Tutorial </h1> <h2> Button Tag <button>autofocus Attribute </button> </h2> <h2> Button Tag <button>autofocus Attribute </button> </h2> <button id="GFG" autofocus> Press </button> <br>
Output:
Example #5
onclick attribute demo. In the below example, I have used JavaScript to take action in the button; meanwhile, it alerts a dialog box with a text message. We use a JavaScript function to make the critical decision by activating the button with onclick().
Code:
<title>HTML On Click Button Demo</title> <h3 id="HTML-On-Click-Button-Demo"> HTML On Click Button Demo</h3> <button onclick="alert('Hi Welcome to EDUCBA!')"> Press me... </button>
Output: Before the button press
Alert Message – After the Button click
Example #6
Code:
<script type="text/javascript" src="scripts.js"> </script> <link rel="stylesheet" href="styles.css"> <script type="text/javascript" src="scripts.js"></script> <link rel="stylesheet" href="styles.css"> <p>The button loads to the next web page!</p> <a href="https://www.educba.com" target="_blank"> <button>Submit!</button> </a>
Output:
Conclusion
In summary, we have learned about the HTML Button tag. This tag initiates an action and submits content within an HTML document. Important aspects of the website create an easy button, CSS, and JavaScript to look colorful. You can also learn many options related to buttons.
以上是HTML 按钮标签的详细内容。更多信息请关注PHP中文网其他相关文章!

HTML用于构建结构清晰的网站。1)使用标签如、、定义网站结构。2)示例展示了博客和电商网站的结构。3)避免常见错误如标签嵌套不正确。4)优化性能通过减少HTTP请求和使用语义化标签。

toinsertanimageIntoanhtmlpage,usethetagwithsrcandaltattributes.1)usealttextforAcccessibilityandseo.2)instementRcsetForresponSiveImages.3)applylazyloadingWithLoadingWithLoading =“ lazy” tooptimizeperformance.4)tooptimizeperformance.4)

HTML的核心目的在于让浏览器理解并展示网页内容。1.HTML通过标签定义网页结构和内容,如、到、等。2.HTML5增强了多媒体支持,引入了和标签。3.HTML提供了表单元素,支持用户交互。4.优化HTML代码可提升网页性能,如减少HTTP请求和压缩HTML。

htmltagsareessentialforwebdevelopmentastheyandendenhancewebpages.1)heSdefinElayout,语义和互动性。2)SemantictagsiCtagSimproveCacsibilitieAndseo.3)pose poseriblesibilityAndseoandseo.3)poser

一致的HTML编码风格很重要,因为它提高了代码的可读性、可维护性和效率。1)使用小写标签和属性,2)保持一致的缩进,3)选择并坚持使用单引号或双引号,4)避免在项目中混合使用不同风格,5)利用自动化工具如Prettier或ESLint来确保风格的一致性。

在Bootstrap4中实现多项目轮播的解决方案在Bootstrap4中实现多项目轮播并不是一件简单的事情。虽然Bootstrap...

如何实现鼠标滚动事件穿透效果?在我们浏览网页时,经常会遇到一些特别的交互设计。比如在deepseek官网上,�...

无法直接通过CSS修改HTML视频的默认播放控件样式。1.使用JavaScript创建自定义控件。2.通过CSS美化这些控件。3.考虑兼容性、用户体验和性能,使用库如Video.js或Plyr可简化过程。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6
视觉化网页开发工具