How To Create a Responsive FAQ page in Blogger For Free
It is very much easy to create a FAQ page in your website for free , just follow the steps Given Below to Create your responsive FAQ page in Blogger For Free .
Step 1 :
Step 2 : (CSS Styling)
<style> @import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;700&display=swap"); h2.faq-heading { font-family: "Inter", sans-serif; text-align: center; font-weight: 300; font-size: 28px; color: #1d3557; margin: 8px 0; margin-top: 60px; } .faq-container { max-width: 600px; border-radius: 8px; box-shadow: 0 4px 50px -8px rgba(0, 0, 0, 0.3); margin: 32px auto; font-family: "Inter", sans-serif; color: #1d3557; line-height: 1.9; } .faq-container .question-container { border-bottom: 1px solid #eee; } .faq-container .question { display: flex; justify-content: space-between; gap: 32px; font-size: 18px; font-weight: bold; padding: 16px 24px; cursor: pointer; } .faq-container .question .question-icon { width: 20px; height: 20px; background: #eee; padding: 4px; border-radius: 50%; flex-shrink: 0; display: flex; transition: all 300ms ease; } .faq-container .question-container.expanded .question-icon { background: #2a9d8f; color: #fff; transform: rotateZ(180deg); } .faq-container .answer { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0; } .faq-container .answer .answer-icon { width: 20px; flex-shrink: 0; color: blue; display: flex; margin-top: 5px; } .faq-container .answer-container { padding: 0px 32px; background: #edf2f4; max-height: 0; overflow: hidden; transition: all 300ms ease; } .faq-container .question-container.expanded .answer-container { max-height: 500px; padding: 8px 32px; } </style>
Copy the above CSS code and paste it in the page you created .
Step 3 : (HEAD Section)
<h2 class="faq-heading"></h2> <div class="faq-container"></div>
Copy this code and paste it below the CSS code you have pasted earlier in the page you have created.
Step 4 : (JAVA SCRIPT Adding Question and anaswers)
<script> const FAQData = [ { question: "Question1 ?", answer: [ "Answer 1.", ], }, { question: "Question 2?", answer: [ "Answer 2", ], }, { question: "Question 3?", answer: [ "Answer 3", ], }, { question: "Question 4?", answer: [ "Answer 4", ], }, { question: "Question 5?", answer: [ "Answer 5.", ], }, ]; const FAQContainer = document.querySelector(".faq-container"); const removeAllExpanded = () => { const questionContainers = document.querySelectorAll( ".faq-container .question-container" ); questionContainers.forEach((q) => { q.classList.remove("expanded"); const answerContainer = q.querySelector(".answer-container"); answerContainer.style.maxHeight = "0"; }); }; const displayFAQ = () => { FAQData.forEach((q) => { const answerHTML = q.answer .map( (a) => `<div class="answer"> <span class="answer-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5" > <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" /> </svg> </span> ${a} </div>` ) .join(""); const html = `<div class="question"> ${q.question} <span class="question-icon" ><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6" > <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" /> </svg> </span> </div> <div class="answer-container"> ${answerHTML} </div>`; const questionContainer = document.createElement("div"); questionContainer.classList.add("question-container"); questionContainer.innerHTML = html; FAQContainer.appendChild(questionContainer); const question = questionContainer.querySelector(".question"); question.addEventListener("click", () => { if (!questionContainer.classList.contains("expanded")) { removeAllExpanded(); } questionContainer.classList.toggle("expanded"); const isExpanded = questionContainer.classList.contains("expanded"); const answerContainer = questionContainer.querySelector(".answer-container"); const contentHeight = answerContainer.scrollHeight; answerContainer.style.maxHeight = isExpanded ? `${contentHeight}px` : "0"; }); }); }; displayFAQ(); </script><script> const FAQData = [ { question: "Question1 ?", answer: [ "Answer 1.", ], }, { question: "Question 2?", answer: [ "Answer 2", ], }, { question: "Question 3?", answer: [ "Answer 3", ], }, { question: "Question 4?", answer: [ "Answer 4", ], }, { question: "Question 5?", answer: [ "Answer 5.", ], }, ]; const FAQContainer = document.querySelector(".faq-container"); const removeAllExpanded = () => { const questionContainers = document.querySelectorAll( ".faq-container .question-container" ); questionContainers.forEach((q) => { q.classList.remove("expanded"); const answerContainer = q.querySelector(".answer-container"); answerContainer.style.maxHeight = "0"; }); }; const displayFAQ = () => { FAQData.forEach((q) => { const answerHTML = q.answer .map( (a) => `<div class="answer"> <span class="answer-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="w-5 h-5" > <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" /> </svg> </span> ${a} </div>` ) .join(""); const html = `<div class="question"> ${q.question} <span class="question-icon" ><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6" > <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" /> </svg> </span> </div> <div class="answer-container"> ${answerHTML} </div>`; const questionContainer = document.createElement("div"); questionContainer.classList.add("question-container"); questionContainer.innerHTML = html; FAQContainer.appendChild(questionContainer); const question = questionContainer.querySelector(".question"); question.addEventListener("click", () => { if (!questionContainer.classList.contains("expanded")) { removeAllExpanded(); } questionContainer.classList.toggle("expanded"); const isExpanded = questionContainer.classList.contains("expanded"); const answerContainer = questionContainer.querySelector(".answer-container"); const contentHeight = answerContainer.scrollHeight; answerContainer.style.maxHeight = isExpanded ? `${contentHeight}px` : "0"; }); }); }; displayFAQ(); </script>
1 : Copy the above JavaScript Code .
2. Paste in Notepad if your are a windows user , Paste it in Quick edit HTML APP if you are a mobile user .
3. After Pasting it in Notepad or Quick Edit Html app It'll look something like this ;
4. Add your Question in the Question section and Answer in the Answer Section.
5.If your answer is more than one line for a particular question then after the 'comma ,' use 'Double apostrophe "answer"' and then add a 'comma ,' in this way You can add multiple lines of answer for a single Question.
6. If you want to increase the number of questions Just Copy below the code and paste it just above the ' ]; ' . and edit it as you want in this way you can as many as questions you want .
{ question: "Question ?", answer: [ "Answer ", ], },
7. After completing all your Questions and Answers prees 'Ctrl+A' to seclect the entire code and press ' Ctrl + C ' to copy the entire code.
8.Now comeback to the FAQ page and paste this code below the head tag and Publish the Page.
9. To make this page more responsive Use our Schema Generator Tool to generate schema and paste the schema at the bottom of all codes that you have pasted earlier.The procedure To Use The tool will be given below the Tool Itself.
10. Once You are done update the page and you're fully reay to use this page in your website.
Video Tutorial :
'Will be available soon'
Post a Comment