CSS for alert () or confirm () JavaScript


I would like you to help me to give css to the alert() and the confirm() of javascript, so that my messages are something elegant, I do not want to opt for a modal only for confirmations, so if someone knew how to I realize I would appreciate it.

  var bool=confirm("Seguro de eliminar el dato?");
    alert("se elimino correctamente");
    alert("cancelo la solicitud");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="confirm">confirmar eliminacion</button>
asked by Shassain 14.08.2017 в 04:53

9 answers


Unfortunately is not possible .

The alert , prompt and confirm are created by the browser and their visual styles depend entirely on it.

Example of Browsers:




Internet Explorer

They are not part of the DOM and therefore can not be applied to styles by CSS or JavaScript.

The only thing you can do is precisely what you mention that you did not want: Use a modal from a library of your choice or make the code yourself .

answered by 14.08.2017 / 07:38

It is not possible to apply css rules to edit the alert() or confirm() .

I recommend Bootbox.js , although they are modals, they are very easy to use and they also have the function to confirm.

    title: "Eliminar Datos",
    message: "Seguro de eliminar el dato?.",
    buttons: {
        cancel: {
            label: '<i class="fa fa-times"></i> Cancelar'
        confirm: {
            label: '<i class="fa fa-check"></i> Confirmar'
    callback: function (result) {
            message: 'Resultado: ' + result
answered by 14.08.2017 в 07:21

There is a very good library, AlertifyJS .

It is responsive and uses jQuery, so it has support in almost all old browsers. You can make a nice and functional confirmation only with these lines of code.

alertify.confirm("This is a confirm dialog.",
  function() {
  function() {
<link href="https://cdn.jsdelivr.net/npm/[email protected]/build/css/alertify.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/alertify.min.js"></script>
answered by 23.11.2017 в 05:33

I recommend you use sweet alert, check the link: link

function delete(id){
    title: Eliminar,
    text: Deseas Eliminar el registro?,
    showCancelButton: true,
    confirmButtonColor: '#f7505a',
    cancelButtonColor: '#f7505a',
    confirmButtonText: 'OK',
    cancelButtonText: 'NO'

}).then(function() {
    swal'Registro Eliminado';


Expanding the answer, download the library and call your function. Note: in the link there are more examples for its use.

answered by 14.08.2017 в 16:32

You can use manners to send alerts, a modal you can design to your liking and it will look the same in all browsers.


W3S Modal

// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");
var btnSi = document.getElementById("myBtnSi");
var btnNo = document.getElementById("myBtnNo");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// Get the button that opens the modal
var mensaje = document.getElementById("myMensaje");

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
    mensaje.textContent  = "Seguro de eliminar el dato?";
    btnSi.style.display = "block";
    btnNo.style.display = "block";

btnSi.onclick = function() {
    mensaje.textContent  = "se elimino correctamente";
    btnSi.style.display = "none";
    btnNo.style.display = "none";

btnNo.onclick = function() {
    mensaje.textContent  = "cancelo la solicitud";
    btnSi.style.display = "none";
    btnNo.style.display = "none";

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;

.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
<!DOCTYPE html>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Eliminar</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p id="myMensaje"></p>
    <button id="myBtnSi">Aceptar</button>
    <button id="myBtnNo">Cancelar</button>


answered by 14.08.2017 в 18:35

You can use SweetAlert is very friendly

        title: "Seguro que quieres hacer esto?",
          text: "Esta acción ya no se podrá deshacer, Así que piénsalo bien.",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Si, estoy seguro',
          cancelButtonText: "Cancelar"
<link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.8.0/sweetalert2.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.8.0/sweetalert2.min.js"></script>
<button id="btnPromt">Mostrar confirmacion</button>

Link: Website

answered by 14.02.2018 в 03:37

Look, if you're looking to replace total functionality on this method ( Alert() ; confirm () )

What you could do is override the function, directly what you do is overwrite that method.

function alert(message) { 


answered by 15.07.2018 в 09:54

I recommend you use the boostrap framework to give you your styles I leave an example:

  <!DOCTYPE html>
<html lang="en">
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>



answered by 14.08.2017 в 05:16

unfortunately you can not from the browser only you can simulate a framework that I use usually for that is: Alertify JS

here is your documentation in English: alertifyjs

and here is a simple example:

  //define a new dialog
        this.message = message;
          return { 
            buttons:[{text: "cool!", key:27/*Esc*/}],
            focus: { element:0 }
//launch it.
alertify.myAlert("Browser dialogs made easy!");

If you want to see an example, look here: examples

answered by 15.07.2018 в 05:58