{"id":22643,"date":"2024-06-10T00:51:05","date_gmt":"2024-06-09T23:51:05","guid":{"rendered":"https:\/\/nelkodev.com\/blog\/todo-lo-que-necesitas-saber-sobre-el-uso-de-modales-en-html\/"},"modified":"2025-09-21T21:00:27","modified_gmt":"2025-09-21T20:00:27","slug":"todo-lo-que-necesitas-saber-sobre-el-uso-de-modales-en-html","status":"publish","type":"post","link":"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/","title":{"rendered":"Everything you need to know about using modals in HTML"},"content":{"rendered":"<p>Modals are very useful components in web development, as they allow you to display pop-up content without interrupting the user experience. In this article, we will teach you how to use modals in HTML effectively. You will learn how to create and customize your own modals to improve usability and interaction on your web pages.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ffffff;color:#ffffff\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ffffff;color:#ffffff\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#%C2%BFQue_es_un_modal_en_HTML\" >What is a modal in HTML?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#Creando_un_modal_basico_en_HTML\" >Creating a basic modal in HTML<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#Personalizando_el_diseno_del_modal\" >Customizing the modal layout<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#Preguntas_frecuentes\" >Frequently asked questions<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#%C2%BFLos_modales_en_HTML_afectan_al_SEO_de_mi_pagina_web\" >Do HTML modals affect the SEO of my website?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#%C2%BFEs_posible_utilizar_modales_sin_JavaScript\" >Is it possible to use modals without JavaScript?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/nelkodev.com\/en\/blog\/everything-you-need-to-know-about-using-modals-in-html\/#%C2%BFExisten_frameworks_o_librerias_que_faciliten_la_creacion_de_modales_en_HTML\" >Are there frameworks or libraries that facilitate the creation of modals in HTML?<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFQue_es_un_modal_en_HTML\"><\/span>What is a modal in HTML?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A modal in HTML is a popup window that overlays the main content of a page. It is used to display additional information, request confirmation, or grab the user&#039;s attention. Modals are often used in cases such as displaying error messages, requesting login information, displaying enlarged images, among others.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Creando_un_modal_basico_en_HTML\"><\/span>Creating a basic modal in HTML<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Next, we&#039;ll show you how to create a basic modal using HTML, CSS, and JavaScript:<\/p>\n<ol>\n<li>First, we will need a basic HTML structure. We create a div with a unique id for the modal and another div for the content of the modal:<\/li>\n<p>   <code><div id=\"myModal\" class=\"modal\"><br \/>\n      <div class=\"modal-content\"><br \/>\n         <span class=\"close\">\u00d7<\/span><br \/>\n         <p>Modal content<\/p><br \/>\n      <\/div><br \/>\n   <\/div><\/code><\/p>\n<li>We add CSS styles for the modal:<\/li>\n<p>   <code>.modal {<br \/>\n      display: none;<br \/>\n      position: fixed;<br \/>\n      z-index: 1;<br \/>\n      left: 0;<br \/>\n      top: 0;<br \/>\n      width: 100%;<br \/>\n      height: 100%;<br \/>\n      overflow: self;<br \/>\n      background-color: rgba(0, 0, 0, 0.4);<br \/>\n   }<\/p>\n<p>   .modal-content {<br \/>\n      background-color: white;<br \/>\n      margin: 15% auto;<br \/>\n      padding: 20px;<br \/>\n      border: 1px solid #888;<br \/>\n      width: 80%;<br \/>\n   }<\/code><\/p>\n<li>We add some JavaScript to show and hide the modal:<\/li>\n<p>   <code>var modal = document.getElementById(&quot;myModal&quot;);<br \/>\n   var btn = document.getElementById(&quot;myBtn&quot;);<br \/>\n   var span = document.getElementsByClassName(&quot;close&quot;)[0];<\/p>\n<p>   btn.onclick = function() {<br \/>\n      modal.style.display = &quot;block&quot;;<br \/>\n   }<\/p>\n<p>   span.onclick = function() {<br \/>\n      modal.style.display = &quot;none&quot;;<br \/>\n   }<\/p>\n<p>   window.onclick = function(event) {<br \/>\n      if (event.target == modal) {<br \/>\n         modal.style.display = &quot;none&quot;;<br \/>\n      }<br \/>\n   }<\/code>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Personalizando_el_diseno_del_modal\"><\/span>Customizing the modal layout<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can customize the layout of the modal using CSS to adapt it to your styles and needs. You can change the colors, add animations, adjust the size, among others. Let your imagination fly and create attractive and functional manners!<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Modals are an excellent tool to improve the user experience on your web pages. Now that you know how to use and customize them, you can give a more interactive touch to your projects. Always remember to optimize the performance of your manners and maintain good usability to offer the best experience to your users.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Preguntas_frecuentes\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"%C2%BFLos_modales_en_HTML_afectan_al_SEO_de_mi_pagina_web\"><\/span>Do HTML modals affect the SEO of my website?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>No, HTML modals do not directly affect the SEO of your website. However, it is important to note that search engines prioritize content visible on the home page. Therefore, if important content is displayed exclusively in a modal, it can affect indexing and visibility in search engines. It is advisable to use manners appropriately and not abuse them.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%C2%BFEs_posible_utilizar_modales_sin_JavaScript\"><\/span>Is it possible to use modals without JavaScript?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>No, HTML modals require JavaScript to function. This is because JavaScript allows you to show and hide the modal dynamically. It is possible to create modality based solely on HTML and CSS using the :target pseudo-class, but this would limit the functionality and customizations possible.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%C2%BFExisten_frameworks_o_librerias_que_faciliten_la_creacion_de_modales_en_HTML\"><\/span>Are there frameworks or libraries that facilitate the creation of modals in HTML?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Yes, there are several frameworks and libraries that make it easy to create HTML modals. Some of the most popular ones are Bootstrap, Foundation and Semantic UI. These frameworks offer pre-styled and fully functional modal components that you can easily implement in your projects.<\/p>","protected":false},"excerpt":{"rendered":"<p>Los modales son componentes muy \u00fatiles en el desarrollo web, ya que permiten mostrar contenido emergente sin interrumpir la experiencia de usuario. En este art\u00edculo, te ense\u00f1aremos c\u00f3mo utilizar los modales en HTML de forma efectiva. Aprender\u00e1s a crear y personalizar tus propios modales para mejorar la usabilidad y la interacci\u00f3n en tus p\u00e1ginas web. [&hellip;]<\/p>","protected":false},"author":0,"featured_media":22644,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[420],"tags":[],"class_list":["post-22643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/22643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/comments?post=22643"}],"version-history":[{"count":0,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/22643\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media\/22644"}],"wp:attachment":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media?parent=22643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/categories?post=22643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/tags?post=22643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}