# Unable to center text when trying to color the background of a section title

I am trying to create a section header with a bold horizontal line on top and a bold horizontal line at the bottom, and a background color that extends to both ends with a centered title. So far I am able to get everything using the solution found at https://tex.stackexchange.com/a/40051/183272, but I cannot figure out how to get the text to center. I am a complete newbie when it comes to TeX, could someone help me with this code?

\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\usepackage{xcolor}

\titleformat{\section}{\bfseries\center}{}{0em}{\hrule height 0.5mm\colorsection}[\hrule height 0.5mm]

\newcommand{\colorsection}[1]{\colorbox{gray!30}{\parbox{\dimexpr\textwidth-2\fboxsep}{\ #1}}}

\begin{document}
\end{document}

• \newcommand{\colorsection}[1]{\colorbox{gray!30}{\parbox{\dimexpr\textwidth-2\fboxsep}{\centering #1}}}might work – leandriis Mar 11 '19 at 20:04
• Welcome to TeX SX! Your sections shouldn't be numbered? – Bernard Mar 11 '19 at 21:46

Here is a very simple way with tcolorbox:

\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{titlesec}
\usepackage[table]{xcolor}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newcommand{\colorsection}[1]{{%
\begin{tcolorbox}[colback=gray!15,halign=center, leftrule=0pt, rightrule=0pt, arc=0mm]\thesection.\enspace#1\end{tcolorbox}}}

\titleformat{\section}[block]{\bfseries}{}{0em}{\colorsection}

\begin{document}