Thẻ progress trong HTML

Thẻ progress trong HTML
Thẻ progress trong HTML

Chức năng của Thẻ progress trong HTML

Thẻ progress trong HTML dùng để kiểm tra các tiến trình tải file, upload file hoặc quá trình hoàn thành biểu mẫu, nó truyền vào 2 giá trị: value (tiến trình hiện tại) và max (giá trị khi hoàn thành).

Code Thẻ progress trong HTML

Thẻ progress mặc định trong HTML

<label for="file">Đang tải tiến trình:</label>
<progress id="file" value="31" max="100"> 31% </progress><br>

<label for="file">Đang tải tiến trình:</label>
<progress id="file" value="70" max="100"> 70% </progress>

Chạy Thử

Thẻ progress hình tròn trong HTML

<!DOCTYPE html>
<html>
<head>
<title>Thẻ progress hình tròn trong HTML</title>
<style>
@property --progress-value {
  syntax: '<integer>';
  inherits: false;
  initial-value: 0;
}

@keyframes html-progress {
  to { --progress-value: 92; }
}

@keyframes css-progress {
  to { --progress-value: 87; }
}

@keyframes js-progress {
  to { --progress-value: 73; }
}

.progress-bar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  
  /* to center the percentage value */
  display: flex;
  justify-content: center;
  align-items: center;
}

.progress-bar::before {
  counter-reset: percentage var(--progress-value);
  content: counter(percentage) '%';
}

.html {
  background: 
    radial-gradient(closest-side, white 79%, transparent 80% 100%),
    conic-gradient(hotpink calc(var(--progress-value) * 1%), pink 0);
  animation: html-progress 2s 1 forwards;
}

.html::before {
  animation: html-progress 2s 1 forwards;
}

.css {
  background: 
    radial-gradient(closest-side, white 79%, transparent 80% 100%, white 0),
    conic-gradient(hotpink calc(var(--progress-value) * 1%), pink 0);
  animation: css-progress 2s 1 forwards;
}

.css::before {
  animation: css-progress 2s 1 forwards;
}

.js {
  background: 
    radial-gradient(closest-side, white 79%, transparent 80% 100%, white 0),
    conic-gradient(hotpink calc(var(--progress-value) * 1%), pink 0);
  animation: js-progress 2s 1 forwards;
}

.js::before {
  animation: js-progress 2s 1 forwards;
}

body {
  font-family: -apple-system, system-ui, Helvetica, Arial, sans-serif;
  margin: 30px auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  max-width: 600px;
}

h2 {
  text-align: center;
}

progress {
  visibility: hidden;
  width: 0;
  height: 0;
}
</style>
</head>
<body>
<h1>Thẻ progress mặc định trong HTML</h1>
<div class="progress-bar-container">
  <h2>
    <label for="html">HTML</label>
  </h2>
  <div class="progress-bar html">
    <progress id="html" min="0" max="100" value="92"></progress>
  </div>
</div>

<div class="progress-bar-container">
  <h2>
    <label for="css">CSS</label>
  </h2>
  <div class="progress-bar css">
    <progress id="css" min="0" max="100" value="87"></progress>
  </div>
</div>

<div class="progress-bar-container">
  <h2>
    <label for="js">JavaScript</label>
  </h2>
  <div class="progress-bar js">
    <progress id="js" min="0" max="100" value="73"></progress>
  </div>
</div>
</body>
</html>

Chạy Thử

Lời kết

Cảm ơn các bạn đã tham khảo bài viết Thẻ progress trong HTML.

  • 0 Bình luận
CEO Bùi Tấn Lực | Founder Web Mới
Bùi Tấn Lực
Tìm hiểu về CEO Bùi Tấn Lực, Founder Web Mới với nhiều năm kinh nghiệm trong lĩnh vực phát triển website, SEO và chia sẻ kiến thức công nghệ
Chia sẻ nội dung đánh giá của bạn về Thẻ progress trong HTML
Email, Điện thoại của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *
Đánh giá của bạn
Tên *
Email
Số điện thoại *
Bình luận, Hỏi đáp
Đăng ký tư vấn thiết kế website
Tìm hiểu 1 năm không bằng lắng nghe 1 câu tư vấn