{"id":25173,"date":"2025-07-04T16:25:03","date_gmt":"2025-07-04T09:25:03","guid":{"rendered":"https:\/\/dps.media\/lam-sao-de-tao-hop-thoai-trong-html\/"},"modified":"2025-07-04T16:25:03","modified_gmt":"2025-07-04T09:25:03","slug":"how-to-create-a-dialog-in-html","status":"publish","type":"post","link":"https:\/\/dps.media\/en\/how-to-create-a-dialog-in-html\/","title":{"rendered":"How to create a dialog box in HTML?"},"content":{"rendered":"<h2>What is the Dialog Element in HTML?<\/h2>\n<p>In HTML, the  element is used to create a dialog box. A dialog box is a small window that appears on the screen to display information or request user input.<\/p>\n<h2>How to add a dialog box to HTML<\/h2>\n<h3>Basic syntax for<\/h3>\n<p>To create a dialog box in HTML, you just need to use the  tag and wrap the dialog content inside this tag.<\/p>\n<p>Example:<\/p>\n<pre><code>&lt;dialog&gt;\n    &lt;p&gt;Hello, this is the content of the dialog.&lt;\/p&gt;\n&lt;\/dialog&gt;<\/code><\/pre>\n<h3>Open and close dialog box<\/h3>\n<p>To open the dialog box, you need to use JavaScript. You can use the method <code>showModal()<\/code> to open the dialog and the method <code>close()<\/code> to close it.<\/p>\n<p>Example:<\/p>\n<pre><code>&lt;button onclick=&quot;openDialog()&quot;&gt;Open dialog&lt;\/button&gt;\n\n&lt;dialog id=&quot;myDialog&quot;&gt;\n    &lt;p&gt;This is the content of the dialog.&lt;\/p&gt;\n    &lt;button onclick=&quot;closeDialog()&quot;&gt;Close&lt;\/button&gt;\n&lt;\/dialog&gt;\n\n<\/code><\/pre>\n<h2>Form inside HTML dialog box<\/h2>\n<p>You can insert forms into the HTML dialog box to request user input or perform actions.<\/p>\n<p>Example:<\/p>\n<pre><code><label for=\"inputName\">Name:<\/label>\n        \n        <button type=\"submit\">Send<\/button><\/code><\/pre>\n<h2>Focus and accessibility in HTML dialog box<\/h2>\n<p>The HTML dialog box will automatically focus on the first element inside the dialog when it is opened. This helps users interact easily with the content inside the dialog.<\/p>\n<p>You can also use the attribute <code>autofocus<\/code> to focus on a specific element inside the dialog.<\/p>\n<p>To ensure accessibility, make sure you use appropriate keyboard shortcuts and provide instructions or notifications when users interact with the dialog.<\/p>\n<h2>Browser support for HTML Dialog<\/h2>\n<p>To check if the browser supports , you can use JavaScript to check its property\/HTML element.<\/p>\n<pre><code>if (\"HTMLDialogElement\" in window) {\n    \/\/ Dialog element supported\n} else {\n    \/\/ Dialog element not supported\n}<\/code><\/pre>\n<h2>Add dialog box with HTML<\/h2>\n<p>With the  element in HTML, you can create simple and easy interactive dialog boxes for your website. Take advantage of this feature to create a better user experience and increase your website's interactivity.<\/p>\n<style>\r\n.lwrp.link-whisper-related-posts{\r\n            \r\n            margin-top: 40px;\nmargin-bottom: 30px;\r\n        }\r\n        .lwrp .lwrp-title{\r\n            \r\n            \r\n        }.lwrp .lwrp-description{\r\n            \r\n            \r\n\r\n        }\r\n        .lwrp .lwrp-list-container{\r\n        }\r\n        .lwrp .lwrp-list-multi-container{\r\n            display: flex;\r\n        }\r\n        .lwrp .lwrp-list-double{\r\n            width: 48%;\r\n        }\r\n        .lwrp .lwrp-list-triple{\r\n            width: 32%;\r\n        }\r\n        .lwrp .lwrp-list-row-container{\r\n            display: flex;\r\n            justify-content: space-between;\r\n        }\r\n        .lwrp .lwrp-list-row-container .lwrp-list-item{\r\n            width: calc(33% - 20px);\r\n        }\r\n        .lwrp .lwrp-list-item:not(.lwrp-no-posts-message-item){\r\n            \r\n            max-width: 150px;\r\n        }\r\n        .lwrp .lwrp-list-item img{\r\n            max-width: 100%;\r\n            height: auto;\r\n            object-fit: cover;\r\n            aspect-ratio: 1 \/ 1;\r\n        }\r\n        .lwrp .lwrp-list-item.lwrp-empty-list-item{\r\n            background: initial !important;\r\n        }\r\n        .lwrp .lwrp-list-item .lwrp-list-link .lwrp-list-link-title-text,\r\n        .lwrp .lwrp-list-item .lwrp-list-no-posts-message{\r\n            \r\n            \r\n            \r\n            \r\n        }@media screen and (max-width: 480px) {\r\n            .lwrp.link-whisper-related-posts{\r\n                \r\n                \r\n            }\r\n            .lwrp .lwrp-title{\r\n                \r\n                \r\n            }.lwrp .lwrp-description{\r\n                \r\n                \r\n            }\r\n            .lwrp .lwrp-list-multi-container{\r\n                flex-direction: column;\r\n            }\r\n            .lwrp .lwrp-list-multi-container ul.lwrp-list{\r\n                margin-top: 0px;\r\n                margin-bottom: 0px;\r\n                padding-top: 0px;\r\n                padding-bottom: 0px;\r\n            }\r\n            .lwrp .lwrp-list-double,\r\n            .lwrp .lwrp-list-triple{\r\n                width: 100%;\r\n            }\r\n            .lwrp .lwrp-list-row-container{\r\n                justify-content: initial;\r\n                flex-direction: column;\r\n            }\r\n            .lwrp .lwrp-list-row-container .lwrp-list-item{\r\n                width: 100%;\r\n            }\r\n            .lwrp .lwrp-list-item:not(.lwrp-no-posts-message-item){\r\n                \r\n                max-width: initial;\r\n            }\r\n            .lwrp .lwrp-list-item .lwrp-list-link .lwrp-list-link-title-text,\r\n            .lwrp .lwrp-list-item .lwrp-list-no-posts-message{\r\n                \r\n                \r\n                \r\n                \r\n            };\r\n        }<\/style>\r\n<div id=\"link-whisper-related-posts-widget\" class=\"link-whisper-related-posts lwrp\">\r\n            <div class=\"lwrp-title\">Related Posts<\/div>    \r\n        <div class=\"lwrp-list-container\">\r\n                                <div class=\"lwrp-list lwrp-list-row-container lwrp-list-double-row\">\r\n                <div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/reliable-blue-tick-verification-service-for-facebook-instagram-dps-media\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">Reputable Facebook Instagram Green Accumulation Service \u2013 DPS.MEDIA<\/span><\/a><\/div><div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/livestream-selling-tips-for-shy-people\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">Livestream selling tips for shy people<\/span><\/a><\/div><div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/what-is-shopee-favorite-shop\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">What is Shopee Favorite Shop? What Are the Conditions for Approval?<\/span><\/a><\/div>                <\/div>\r\n                            <div class=\"lwrp-list lwrp-list-row-container lwrp-list-double-row\">\r\n                <div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/how-to-get-the-green-verification-badge-on-facebook-effectively\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">How to Effectively Get a Blue Checkmark on Facebook<\/span><\/a><\/div><div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/tiktok-ads-conversion-tracking-standard-guide\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">TikTok Ads Conversion Tracking: Official Guide<\/span><\/a><\/div><div class=\"lwrp-list-item\"><a href=\"https:\/\/dps.media\/en\/how-to-optimize-tiktok-pixel-to-increase-conversions\/\" class=\"lwrp-list-link\"><span class=\"lwrp-list-link-title-text\">How to Optimize TikTok Pixel to Increase Conversions<\/span><\/a><\/div>                <\/div>\r\n                <\/div>\r\n<\/div>","protected":false},"excerpt":{"rendered":"<p>What is the Dialog Element in HTML? In HTML, the  element is used to create a dialog box. A dialog box is a small window that appears on the screen to display information or request user input. How to add a dialog box to HTML Basic syntax for  [\u2026]<\/p>","protected":false},"author":1,"featured_media":25174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[84,1],"tags":[],"class_list":["post-25173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-affiliate-marketing","category-uncategorized"],"acf":[],"rankmath_keywords":{"primary":"","secondary":[""]},"yoast_keywords":{"primary":"","secondary":[]},"yoast_focuskw":"","rankmath_focuskw":"","seo_keywords":{"primary":"","secondary":[""]},"_links":{"self":[{"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/posts\/25173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/comments?post=25173"}],"version-history":[{"count":0,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/posts\/25173\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/media\/25174"}],"wp:attachment":[{"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/media?parent=25173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/categories?post=25173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dps.media\/en\/wp-json\/wp\/v2\/tags?post=25173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}