Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="main">
  <div id="container">
<h1>Are You Satisfied with our Service?</h1>

<form id="form" action="main.php">
	<i star-rating="1" class="fas fa-star star"></i>
	<i star-rating="2" class="fas fa-star star"></i>
	<i star-rating="3" class="fas fa-star star"></i>
	<i star-rating="4" class="fas fa-star star"></i>
	<i star-rating="5" class="fas fa-star star"></i>
	<input type="number" name="rating" id="ratingInput" value="3" style="display: none;">
	<input type="submit" value="Submit">
</form>
  </div>
</div>
  
<div>
	<p id="ratingVal">Click on the Stars to Rate them!</p>
</div>
              
            
!

CSS

              
                /* Dynamic  Variables */

:root {
  --Color:green;
}

i {
  &.hoveredStars, &.clickedStars {
    background-color: var(--Color);
  }
}

/* Document Styles, the below are actually Unnecessary */

* {
  background-color: #def4f0;
  color: black;
  text-align: center;
  font-family: sans-serif;
  font-size: 24px;
}

h1 {
  font-size: 1.75em;
  color: #444;
}

#main {
  position: absolute;
  margin: 0 auto;
  top: 25%;
  left: 50%;
}

#container {
  position: relative;
  left: -50%;
}

form {
  margin-top: 65px;

  > * {
    display: inline-block;
  }

  input[type="submit"] {
    background-color: #400082;
    color: white;
    margin: 25px 25px 0 0;
    padding: 10px;
    border-radius: 15px;
    transition: 0.1s ease-in-out;

    &:hover {
      background-color: #200052;
      transform: translate(0, -3px);
    }

    &:active {
      transform: translate(0, 1px);
    }
  }
}

#ratingVal {
  position: absolute;
  color: white;
  bottom: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.9);
  padding: 12px 20px;
  font-family: sans-serif;
  border-radius: 5px;
}

/* Icons, somewhat necessary */

form > i {
  user-select: none;
  color: white;
  background-color: #bbb;
  font-size: 1.2em;
  transition: .1s ease-in-out;
  padding: 10px;
  border-radius: 10px;

  &:hover {
    box-shadow: 1px 1.5px 3px #555;
    transform: translate(0, -3px);
  }

  &:active {
    transform: translate(0, 1px);
  }
}
              
            
!

JS

              
                // https://codepen.io/Betich/pen/XWmOaRE

var hues = [53, 30, 14, 344, 0]; // Color Scheme based on hue

$(document).ready(function() {
  var stars = $(".star");
	var rating = parseInt($("#ratingInput").val());
	const ratingPreview = $("#ratingVal");
	
  var Star = {
    onClicked: function() {
			// Determine Input Value
		$("#ratingInput").val($(this).attr("star-rating"));
			rating = parseInt($("#ratingInput").val());
			judgeRating(ratingPreview, rating);
			
			// Assign Colors
      $(this).siblings()
				.filter(".star").removeClass("clickedStars"); // Reset Color
      assignColor(hues[rating - 1], "Color");
      $(this).prevAll().addBack().addClass("clickedStars");
    },

    onHovered: function() {
      const currIndex = $(this).index();
			
			// If the hovered star is higher than the clicked star,
			// Assign the current star's color value to all stars
			var ratingIdx = rating - 1; // Rating Index
      if (currIndex > ratingIdx) {
        assignColor(hues[currIndex], "Color");
      }

      $(this).prevAll().addBack().addClass("hoveredStars");
			
			let hovRating = parseInt($(this).attr("star-rating"));
			judgeRating(ratingPreview, hovRating);
    },
		
		unHover: function() {
			// Reset Color
    	$(this).prevAll().addBack()
      	.removeClass("hoveredStars");
			assignColor(hues[rating - 1], "Color");
			
			// Change Rating Text
			if (rating) { judgeRating(ratingPreview, rating); }
			else { ratingPreview.text("Click on the Stars to Rate them!"); }
  	}
  };
	
	/* INIT: Set up stars beforehand */
	init(stars, rating);
	
	/* Star Events */
  stars.click(Star.onClicked);
  stars.hover(Star.onHovered, Star.unHover);
});

// Functions

function init(obj, initRating) {
	judgeRating($("#ratingVal"), initRating);
	
	initRating--; // Convert to Array Index
	let initStar = obj.get(initRating);
			
	// Assign Colors
  $(initStar).siblings()
		.filter(".star").removeClass("clickedStars"); // Reset Color
  assignColor(hues[initRating], "Color");
  $(initStar).prevAll().addBack().addClass("clickedStars");
}

function assignColor(hue, assignedVar) {
  const sat = "85%",
    		val = "55%"; // Saturation & Value
  document.documentElement.style.setProperty(
    "--" + assignedVar,
    "hsl(" + hue + "," + sat + "," + val + ")"
  );
}

function judgeRating(selector, rating) {
	var reaction = (rating) => {
		switch(rating) {
			case 1:
				return "Terrible!"
				break;
			case 2:
				return "Eh, could've been better."
				break;
			case 3:
				return "Okay, I guess."
				break;
			case 4:
				return "This is great!"
				break;
			case 5:
				return "Wow! As good as it gets!"
				break;
			default:
				return "ERR: you shouldn't be able to see this value..."
		}
	};
	selector.text(
		"Rating: " + rating +
		",\t\t" + reaction(rating)
	);
}
              
            
!
999px

Console